/
Unit1.pas
223 lines (186 loc) · 4.7 KB
/
Unit1.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, jpeg, Menus,ShellAPI,Registry;
const
WM_NID = WM_USER+1000;
type
TForm1 = class(TForm)
image1: TImage;
label1: TLabel;
shape1: TShape;
timer1: TTimer;
label2: TLabel;
pm1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
dlgOpen1: TOpenDialog;
timer3: TTimer;
timer4: TTimer;
N4: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure timer1Timer(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure timer3Timer(Sender: TObject);
procedure timer4Timer(Sender: TObject);
procedure SetAutorun(aProgTitle,aCmdLine: string; aRunOnce: boolean );
procedure WMNID(var msg:TMessage);message WM_NID;
procedure N4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2 ;
const
rc=90;
var
p: array[0..359] of tpoint;
flag:Boolean = False;
j:Integer = 10;
NotifyIcon:TNotifyIconData;//全局变量
{$R *.dfm}
procedure tform1.WMNID(var msg:TMessage);
var
a:TPoint;
begin
form1.Visible:=False;
case msg.LParam of
WM_LBUTTONUP:
begin
ShowWindow(Form1.Handle,SW_SHOWNORMAL);
SetForegroundWindow(Form1.Handle);//记住这两个函数
end;
WM_RBUTTONUP:
begin
GetCursorPos(a);
pm1.Popup(a.X,a.Y);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
x,y: real;
a: integer;
rgn: hrgn;
begin
SetAutorun(Application.Title,application.ExeName,false);
with NotifyIcon do
begin
cbSize:=SizeOf(TNotifyIconData);
Wnd:=handle;
uID:=1;
uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage:=WM_NID;
hIcon:=Application.Icon.Handle;
szTip:='小时钟';
end;
SetWindowLong(Application.Handle,GWL_EXSTYLE, WS_EX_TOOLWINDOW or WS_EX_STATICEDGE);
Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
for a:=0 to 359 do
begin
x:= rc*cos(a*pi/180)+rc;
y:= rc-rc*sin(a*pi/180);
p[a].x:=trunc(x);
p[a].y:=trunc(y);
end;
rgn:=createpolygonrgn(p, 360, winding);
setwindowrgn(handle, rgn, true);
clientwidth:=rc+rc;
clientheight:=rc+rc;
top:=10;
left:=screen.width-width-10;
showhint:=true;
hint:='点击右键关闭哦^_^';
shape1.width:=rc+rc+1;
shape1.height:=rc+rc+1;
shape1.top:=-1;
shape1.left:=-1;
image1.width:=rc+rc div 2+25+5;
image1.height:=rc+rc div 2+25+5;
image1.top:=rc div 2-25-10-3;
image1.left:=rc div 2-25-10-3;
label1.Top:=rc div 2+50;
label1.Left:=rc div 2;
label2.Left:=rc div 2;
label2.Top:=rc div 2+50+25;
end;
procedure TForm1.timer1Timer(Sender: TObject);
begin
label1.Caption:=TimeToStr(time);
label2.Caption:=DateToStr(Date);
end;
procedure TForm1.N1Click(Sender: TObject);
begin
dlgOpen1.Filter:='图片文件(*.jpg)|*.JPG';
if dlgOpen1.Execute then
begin
image1.Picture.LoadFromFile(dlgOpen1.FileName);
end
else
Exit;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
form2.Show;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
ShellExecute(Handle,'open','http://lovewzan.3vzhuji.com/index.html',nil,nil,SW_SHOWNORMAL) ;
end;
procedure TForm1.timer3Timer(Sender: TObject);
begin
if flag then
begin
Form1.top:=Form1.top+3;
end
else
Form1.top:=Form1.top-3;
flag:=not flag;
end;
procedure TForm1.timer4Timer(Sender: TObject);
begin
AlphaBlendValue:=j;
j:=j+10;
if j = 230 then
timer4.Destroy;
end;
procedure TForm1.SetAutorun(aProgTitle,aCmdLine: string; aRunOnce: boolean );
var
hKey: string;
hReg: TRegIniFile;
begin
if aRunOnce then
//程序只自动运行一次
hKey := 'Once'
else
hKey := '';
hReg := TRegIniFile.Create('');
//TregIniFile类的对象需要创建
hReg.RootKey := HKEY_LOCAL_MACHINE;
//设置根键
hReg.WriteString('Software\Microsoft\Windows\CurrentVersion\Run'
+ hKey + #0,
aProgTitle,
//程序名称,可以为自定义值
aCmdLine );
//命令行数据,必须为该程序的绝对路径+程序完整名称
hReg.destroy;
//释放创建的hReg
end;
procedure TForm1.N4Click(Sender: TObject);
begin
if idok = MessageBox(Handle,'你确定?','提示',MB_OKCANCEL or MB_ICONQUESTION) then
begin
Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
close;
end;
end;
end.