This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUMain.pas
More file actions
233 lines (201 loc) · 4.96 KB
/
UMain.pas
File metadata and controls
233 lines (201 loc) · 4.96 KB
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
224
225
226
227
228
229
230
231
232
unit UMain;
interface
uses
Classes, Forms, ShellAPI, WinTypes, Messages, Menus;
type
TMainForm = class(TForm)
MainMenu: TMainMenu;
mFile: TMenuItem;
mExit: TMenuItem;
mView: TMenuItem;
mRefresh: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
N2: TMenuItem;
IE1: TMenuItem;
S1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Config1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure mExitClick(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure IE1Click(Sender: TObject);
procedure S1Click(Sender: TObject);
private
IsLiveTasktray: boolean;
NotifyIcon: TNotifyIconData;
procedure InitTasktray;
procedure FinishTasktray;
procedure MovetoTasktray;
procedure LeaveTasktray;
procedure AppMinimize(Sender: TObject);
procedure AppRestore(Sender: TObject);
protected
procedure WndProc(var Message: TMessage); override;
end;
var
MainForm: TMainForm;
implementation
uses
Transport, Http, Cache, Config, StrSub,
UConfig, UAbout, UTerminate;
{$R *.DFM}
const
WM_NotifyTasktray = WM_USER + 100;
var
ConfigForm: TConfigForm;
AboutForm : TAboutForm;
TerminateForm : TTerminateForm;
TransportDaemon: TDaemon;
HttpDaemon: THttp;
procedure TMainForm.WndProc(var Message: TMessage);
begin
if Message.Msg = WM_NotifyTasktray then begin
case Message.LParam of
WM_LBUTTONUP:
begin
LeaveTasktray;
Application.Restore;
end;
end;
end else begin
inherited;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Randomize;
FConfig := TConfig.Create;
FConfig.Load;
FCache := TCache.Create;
Application.OnMinimize := AppMinimize;
Application.OnRestore := AppRestore;
IsLiveTaskTray := false;
if FConfig.FIconize then begin
Application.ShowMainForm := false;
MoveToTaskTray;
end;
Caption := 'Crescent v.' + CrescentVersion;
HttpDaemon := THttp.Create;
HttpDaemon.Start;
TransportDaemon := TDaemon.Create(true);
TransportDaemon.Resume;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
ARect: TRect;
begin
if TerminateForm = nil then begin
TerminateForm := TTerminateForm.Create(self);
GetWindowRect(MainForm.Handle,ARect);
TerminateForm.Top := ARect.Top + (MainForm.Height - TerminateForm.Height) div 2;
TerminateForm.Left := ARect.Left + (MainForm.Width - TerminateForm.Width) div 2;
TerminateForm.Show;
TerminateForm.Update;
FinishTasktray;
FTerminateFlag := true;
TransportDaemon.Terminate;
HttpDaemon.Free;
TransportDaemon.Free;
FCache.Free;
FConfig.Free;
TerminateForm.Hide;
TerminateForm.Free;
TerminateForm := nil;
end;
end;
procedure TMainForm.AppMinimize(Sender: TObject);
begin
MovetoTasktray
end;
procedure TMainForm.AppRestore(Sender: TObject);
begin
end;
procedure TMainForm.InitTasktray;
begin
if IsLiveTasktray then begin
exit;
end;
with NotifyIcon do begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uID := 1;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallbackMessage := WM_NotifyTasktray;
hIcon := Application.Icon.Handle;
szTip := 'Crescent';
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
IsLiveTasktray := true;
end;
procedure TMainForm.FinishTasktray;
begin
if IsLiveTasktray = False then begin
exit;
end;
with NotifyIcon do begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uID := 1;
end;
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
IsLiveTasktray := False;
end;
procedure TMainForm.MovetoTasktray;
begin
InitTasktray;
Hide;
end;
procedure TMainForm.LeaveTasktray;
begin
FinishTasktray;
Show;
end;
procedure TMainForm.Config1Click(Sender: TObject);
begin
if ConfigForm = nil then begin
ConfigForm := TConfigForm.Create(self);
ConfigForm.ShowModal;
ConfigForm.Free;
ConfigForm := nil;
end;
end;
procedure TMainForm.About1Click(Sender: TObject);
begin
if AboutForm = nil then begin
AboutForm := TAboutForm.Create(self);
AboutForm.Label1.Caption := 'Crescent v.' + CrescentVersion;
AboutForm.ShowModal;
AboutForm.Free;
AboutForm := nil;
end;
end;
procedure TMainForm.mExitClick(Sender: TObject);
begin
Close;
end;
procedure TMainForm.N2Click(Sender: TObject);
var
SI: TStartupInfo;
PI: TProcessInformation;
s: string;
begin
GetStartupInfo(SI);
s := 'explorer.exe /e,"' + FConfig.FFolder + '"';
CreateProcess(
nil, pchar(s), nil, nil,
false, CREATE_DEFAULT_ERROR_MODE, nil, nil, SI, PI
);
end;
procedure TMainForm.IE1Click(Sender: TObject);
begin
ShellExecute(0, 'open', Pchar('http://localhost:' + FConfig.FPort + '/gateway.cgi/'),
nil, nil, SW_SHOW);
end;
procedure TMainForm.S1Click(Sender: TObject);
begin
ShellExecute(0, 'open', Pchar('http://shingetsu.sourceforge.net/'),
nil, nil, SW_SHOW);
end;
end.