pomodoro源码
Posted yxysuanfa
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pomodoro源码相关的知识,希望对你有一定的参考价值。
有网友问我要pomodoro源码。事实上这个程序非常easy,仅仅是定时器,定时弹出置顶窗体。用c++builder6.0写。放一个TPopupMenu 右键菜单,一个TTrayIcon 一个托盘图标控件
。一个ImageList1图片列表,显示闪动图片。显示时间的标签。
源码例如以下,假设不用C++builder写,仅仅能參考代码自己写。
定时器推断时间到了就显示窗体。闪动图标。双击关闭窗体。
unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include "trayicon.h"
#include <Menus.hpp>
#include <ImgList.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTimer *Timer1;
TLabel *LMinute;
TLabel *LMaohao;
TLabel *LSecond;
TTrayIcon *TrayIcon1;
TPopupMenu *PopupMenu1;
TMenuItem *N1;
TImageList *ImageList1;
TMenuItem *sinoxorg1;
TMenuItem *N2;
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall N1Click(TObject *Sender);
void __fastcall FormDblClick(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall TrayIcon1Restore(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall sinoxorg1Click(TObject *Sender);
void __fastcall FormKeyPress(TObject *Sender, char &Key);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <registry.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"
TForm1 *Form1;
int iWaitTime=0;
int MaxWaitTime=25*60;
int MaxRestTime=5*60;
int RunState=0;
int IsOwnerPress=false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
RunState=0;
IsOwnerPress=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
iWaitTime+=1;
if (RunState==0)
{
if ( iWaitTime>= MaxWaitTime)
{
RunState=1;
iWaitTime=0;
}
Color= clBtnFace;
LMinute->Color= clBtnFace;
LMaohao->Color= clBtnFace;
LSecond->Color= clBtnFace;
LMinute->Caption=iWaitTime/60;
LSecond->Caption=iWaitTime%60;
if ( iWaitTime%5==0)
{
if (WindowState!=wsMinimized)
{
WindowState=wsMinimized;
Hide();
}
}
IsOwnerPress=false;
TrayIcon1->Animate=false;
//randomize();
//TrayIcon1->SetIconIndex(rand() % 3);
TrayIcon1->SetIconIndex(1);
}
else
{
if ( iWaitTime>= MaxRestTime)
{
RunState=0;
iWaitTime=0;
IsOwnerPress=false;
}
Color= clRed;
LMinute->Color= clRed;
LMaohao->Color= clRed;
LSecond->Color= clRed;
LMinute->Caption=iWaitTime/60;
LSecond->Caption=iWaitTime%60;
if(IsOwnerPress)
{
if ( iWaitTime%5==0)
{
if (WindowState!=wsMinimized)
{
WindowState=wsMinimized;
Hide();
}
}
}
else
{
if (WindowState==wsMinimized)
{
WindowState=wsNormal;
Show();
}
TrayIcon1->Animate=true;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N1Click(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDblClick(TObject *Sender)
{
WindowState=wsMinimized;
Hide();
IsOwnerPress=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
WindowState=wsMinimized;
Action=caNone;
Hide();
IsOwnerPress=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrayIcon1Restore(TObject *Sender)
{
WindowState=wsNormal;
Show();
IsOwnerPress=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TRegistry *Test;
Test = new TRegistry ();
Test->RootKey = HKEY_LOCAL_MACHINE;
if(Test->OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",false))
{
AnsiString sKeyval;
sKeyval=Test->ReadString("sinox_pomodoro");
if (sKeyval.Length()<=4)
Test->WriteString("sinox_pomodoro",Application->ExeName);
}
delete Test ;
randomize();
TrayIcon1->SetIconIndex(rand() % 3);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::sinoxorg1Click(TObject *Sender)
{
AnsiString strurl= "http://www.sinox.org/";
ShellExecute(NULL,NULL, strurl.c_str(),NULL,NULL,SW_SHOW);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
if (Key==VK_SPACE)
{
WindowState=wsMinimized;
Hide();
IsOwnerPress=true;
}
}
//---------------------------------------------------------------------------
unit1.dfm
object Form1: TForm1
Left = 192
Top = 114
Width = 870
Height = 145
BorderIcons = [biSystemMenu]
BorderStyle = bsSizeToolWin
Color = clBtnFace
DefaultMonitor = dmDesktop
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -24
Font.Name = ‘MS Sans Serif’
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = False
Position = poDesktopCenter
OnClose = FormClose
OnCreate = FormCreate
OnDblClick = FormDblClick
OnKeyPress = FormKeyPress
PixelsPerInch = 96
TextHeight = 29
object LMinute: TLabel
Left = 349
Top = 16
Width = 44
Height = 33
AutoSize = False
Caption = ‘0’
end
object LMaohao: TLabel
Left = 400
Top = 16
Width = 32
Height = 33
AutoSize = False
Caption = #65306
end
object LSecond: TLabel
Left = 440
Top = 16
Width = 57
Height = 33
AutoSize = False
Caption = ‘0’
end
object Timer1: TTimer
OnTimer = Timer1Timer
Left = 448
Top = 80
end
object TrayIcon1: TTrayIcon
Visible = True
Hint = #24037#20316#20241#24687#25552#37266#22120
PopupMenu = PopupMenu1
Hide = True
RestoreOn = imDoubleClick
PopupMenuOn = imRightClickUp
Icons = ImageList1
IconIndex = 1
OnRestore = TrayIcon1Restore
Left = 320
Top = 80
end
object PopupMenu1: TPopupMenu
Left = 88
Top = 72
object N1: TMenuItem
Caption = #20851#38381
OnClick = N1Click
end
object sinoxorg1: TMenuItem
Caption = #35775#38382’sinox.org’
OnClick = sinoxorg1Click
end
object N2: TMenuItem
Caption = #21452#20987’/’#25353#31354#26684#38544#34255
end
end
object ImageList1: TImageList
AllocBy = 3
Left = 200
Top = 80
Bitmap = {
494C010103000400040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000001000000001002000000000000010
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000909E9003434
760032327C000405F60000000000000000000000000000000000000000003030
8300363671000909E900000000000000000000000000000000000909E9003434
760032327C000405F70000000000000000000000000000000000000000003030
8300363671000909E900000000000000000000000000000000000909E9003131
7700313177000505F60000000000000000000000000000000000000000003030
8300363671000909E90000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000002A2A95005354
21004E4C3100311D950029209E0031446E0031446E002B2597002F1B9A004E4C
31005354210030308300000000000000000000000000000000002A2A95005253
26004E4C2F0031218400282196002F4481002F4481002A2A95002F1A85004F4B
2F005253260030308300000000000000000000000000000000002A2A95005454
21004B4B33001D1D950021219E0042446E0042446E00252796001B1A9A004B4B
3300545421003030830000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000001012D600453D
54004B3E47002E95210011E9000009F9000009F9000011E9000027A819004844
4500473C4F001315CD00000000000000000000000000000000001112D500453D
4C004A3F3B002D96880013E5CD0008FAE90008FAE90010EBD30029A291004745
4100473C45001315CF00000000000000000000000000000000001212D6003C3C
50003C3C500095962000E4E50000FAFB0000FAFB0000E9EB0000A1A21A004445
45003C3C50001515CD0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000003831
780019CE0B0000FF000000FF000000FF000000FF000000FF000000FF000012DC
07003A4064000000000000000000000000000000000000000000000000003731
720018D0BF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0011DD
D00039416C000300F80000000000000000000000000000000000000000003131
7700CED00A00FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000DCDD
0600414164000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000002510B50025BF
090000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF
00001CD302002D1B9D000000000000000000000000000000000025109F0023C0
A30000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FF
FF001AD5B8002C1C8D0000000000000000000000F8000000F8001010B500BFC0
0800FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF
0000D4D501001B1A9A0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000003457570000FF
000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF
000000FF0000336F3F000900F80000000000000000000300F80033587A0002FF
F90000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FF
FF0000FFFF0032717B000800EB0000000000000000000000000057585600FFFF
0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF
0000FFFF00006F713E000000F8000000F8000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000F00EF002D8E2B0000FF
000000FF000000FF000000FF000019C1190021AD21000BE10B000BE10B000BE1
0B0000FF000027A819001400E20000000000000000000F00DB002B8B8E0000FF
FF0000FFFF0000FFFF0000FFFF001AC3B9001FAEAE000AE5E3000BDFDD000AE5
E30000FFFF0026AA9A001400CC0000000000000000000000EF008E8F2A00FFFF
0000FFFF0000FFFF0000FFFF0000C1C21700AEAE1F00E3E50A00DEDF0D00E2E4
0A00FFFF0000A8AA17000000E200000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000001100EA002A97240000FF
000000FF000000FF000000FF00002D8E2B003B663B001EB21E0021A721001EB2
1E0000FF000023B612001600DD0000000000000000001000D7002A97910000FF
FF0000FFFF0000FFFF0000FFFF002A979100396967001BB7B3001EADA8001BB7
B30000FFFF0022B8A6001600C60000000000000000000000EF0097992300FFFF
0000FFFF0000FFFF0000FFFF00009092290067693900B3B71B00A8AD1E00B3B7
1B00FFFF0000B6B811000000DD00000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000900F8002E7E380000FF
000000FF000000FF000000FF00000CE30C000FDF0F0000FF000000FF000000FF
000000FF00002A9724000F00EF0000000000000000000A00E7002D84880000FF
FF0000FFFF0000FFFF0000FFFF000AE5E3000AE5E30000FFFF0000FFFF0000FF
FF0000FFFF002A9791001000D7000000000000000000000000007E803600FFFF
0000FFFF0000FFFF0000FFFF0000E2E40A00E2E40A00FFFF0000FFFF0000FFFF
0000FFFF0000979923000000EF00000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000303083000DF8
000000FF000000FF000000FF00000FDF0F0012D6120000FF000000FF000000FF
000000FF0000314A6800000000000000000000000000000000002D348A000BF9
DF0000FFFF0000FFFF0000FFFF000DDFDE000FD7D60000FFFF0000FFFF0000FF
FF0007FFEC00304C82000000000000000000000000000000000030308300F8F9
0000FFFF0000FFFF0000FFFF0000DEDF0D00D6D70F00FFFF0000FFFF0000FFFF
0000FFFF00004A4C670000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000001C1DB7001C08CD002F82
340000FF000000FF000000FF00000FDF0F0012D6120000FF000000FF000000FF
00002A9D22001E07CB001C1DB70000000000000000001C1DB7001D07B4002D84
880000FFFF0000FFFF0000FFFF000DDFDE000FD7D60000FFFF0000FFFF0000FF
FF00299E93001D07B4001C1DB70000000000000000001E1EB2000707CD008384
3200FFFF0000FFFF0000FFFF0000DEDF0D00D6D70F00FFFF0000FFFF0000FFFF
00009D9E21000707CD001E1EB200000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000202F90043434F003F405800210B
C4002C89310009F9000000FF000008F7080009EE090000FF000008FF00002A9D
2200230FBB00343476004A4A3E000909E9000405F70043434F003F405800200B
AE002B8B8E0009FDE60000FFFF0004F4F30007EFED0000FFFF0007FFEC00299E
9300240FA700343476004A4A3D000909E9000505F60043434F00404058000B0B
C100898B3000FAFB0000FFFF0000EEEF0700EEEF0700FFFF0000FFFF00009D9E
21000F0FBB00313177004A4A3E000909E9000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000034347600535421003F40
5800210BC4002F4274002A9827001CBF13001CBF13002A9D2200314A6800210B
C4003A386A00535421003F4058000405F6000000000034347600535421003F40
5800200BAE0029428C00299E93001BC0B6001BC0B600299E93002E4F8700200B
AE003A386900535421003F4058000405F7000000000036367100545421004040
58000D0CC0004343730097992300BFC01100BFC011009D9E21004E4F67000B0B
C30038386A0054542100404058000505F6000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000909E90032327C003B3B
6400181AC100000000000F00EF003B277A003B277A001100EA00000000001012
D6003B3B6400343476000E0EDC0000000000000000000909E90032327C003B3B
6400181AC300000000000F00DB003B2866003B2866001000D700000000001112
D5003B3B6400343476000E0EDC0000000000000000000909E90032327C003B3B
64001A1AC100000000000000EF0028287900282879000000EF00000000001212
D6003B3B6400363671000E0EDC00000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000708EE000708EE0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000708EF000708EF0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000808EE000808EE0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000424D3E000000000000003E000000
2800000040000000100000000100010000000000800000000000000000000000
000000000000000000000000FFFFFF00FFFFFFFFFFFF0000C3E3C3E3C3E30000
C003C003C0030000C003C003C0030000E007E003E0070000C003C00300030000
C0018001C00000008001800180010000800180018001000080018001C0010000
C003C003C0030000800180018001000000000000000000008000800080000000
8421842184210000FE7FFE7FFE7F0000}
end
end
能够建立一个项目后替换这三个文件。
以上是关于pomodoro源码的主要内容,如果未能解决你的问题,请参考以下文章
Android 逆向类加载器 ClassLoader ( 类加载器源码简介 | BaseDexClassLoader | DexClassLoader | PathClassLoader )(代码片段
初识Spring源码 -- doResolveDependency | findAutowireCandidates | @Order@Priority调用排序 | @Autowired注入(代码片段
初识Spring源码 -- doResolveDependency | findAutowireCandidates | @Order@Priority调用排序 | @Autowired注入(代码片段
Android 插件化VirtualApp 源码分析 ( 目前的 API 现状 | 安装应用源码分析 | 安装按钮执行的操作 | 返回到 HomeActivity 执行的操作 )(代码片段
Android 事件分发事件分发源码分析 ( Activity 中各层级的事件传递 | Activity -> PhoneWindow -> DecorView -> ViewGroup )(代码片段