@@ -12,7 +12,7 @@ TMain = class(TForm)
1212 IdHTTPServer: TIdHTTPServer;
1313 CommandKeyEdt: TEdit;
1414 CommandLbl: TLabel;
15- PopupMenu : TPopupMenu;
15+ PopupMenuApp : TPopupMenu;
1616 CloseBtn: TMenuItem;
1717 AboutBtn: TMenuItem;
1818 LineBtn: TMenuItem;
@@ -41,12 +41,13 @@ TMain = class(TForm)
4141 procedure CancelBtnClick (Sender: TObject);
4242 procedure AllowAnyIPsCBClick (Sender: TObject);
4343 procedure AllowedIPsMemoChange (Sender: TObject);
44+ procedure FormActivate (Sender: TObject);
4445 private
4546 procedure DefaultHandler (var Message); override;
4647 { Private declarations }
4748 protected
4849 procedure IconMouse (var Msg: TMessage); message WM_USER + 1 ;
49- procedure WMActivate (var Msg: TMessage); message WM_ACTIVATE;
50+ // procedure WMActivate(var Msg: TMessage); message WM_ACTIVATE;
5051 public
5152 procedure AppShow ;
5253 procedure AppHide ;
@@ -55,7 +56,7 @@ TMain = class(TForm)
5556
5657var
5758 Main: TMain;
58- RunOnce, DebugMode: boolean;
59+ DebugMode: boolean;
5960 WM_TASKBARCREATED: Cardinal;
6061 AllowClose: boolean = false;
6162 AllowedIPs: TStringList;
@@ -214,7 +215,8 @@ procedure TMain.IdHTTPServerCommandGet(AThread: TIdPeerThread;
214215 // CoUninitialize;
215216end ;
216217
217- procedure Tray (ActInd: integer); // 1 - äîáàâèòü, 2 - èçìåíèòü, 3 - óäàëèòü
218+ type TTrayAction = (TrayAdd, TrayUpdate, TrayDelete);
219+ procedure Tray (TrayAction: TTrayAction);
218220var
219221 NIM: TNotifyIconData;
220222begin
@@ -223,14 +225,14 @@ procedure TMain.IdHTTPServerCommandGet(AThread: TIdPeerThread;
223225 Wnd:=Main.Handle;
224226 uId:=1 ;
225227 uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
226- hIcon:=SendMessage(Application .Handle, WM_GETICON, ICON_SMALL2, 0 );
228+ hIcon:=SendMessage(Main .Handle, WM_GETICON, ICON_SMALL2, 0 );
227229 uCallBackMessage:=WM_USER + 1 ;
228230 StrCopy(szTip, PChar(Application.Title));
229231 end ;
230- case ActInd of
231- 1 : Shell_NotifyIcon(NIM_ADD, @NIM);
232- 2 : Shell_NotifyIcon(NIM_MODIFY, @NIM);
233- 3 : Shell_NotifyIcon(NIM_DELETE, @NIM);
232+ case TrayAction of
233+ TrayAdd : Shell_NotifyIcon(NIM_ADD, @NIM);
234+ TrayUpdate : Shell_NotifyIcon(NIM_MODIFY, @NIM);
235+ TrayDelete : Shell_NotifyIcon(NIM_DELETE, @NIM);
234236 end ;
235237end ;
236238
@@ -248,10 +250,8 @@ procedure TMain.FormCreate(Sender: TObject);
248250 Ini: TIniFile;
249251begin
250252 Application.Title:=Caption;
251- AppHide;
252253 WM_TASKBARCREATED:=RegisterWindowMessage(' TaskbarCreated' );
253- Tray(1 );
254- SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
254+ // SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
255255
256256 if GetLocaleInformation(LOCALE_SENGLANGUAGE) = ' Russian' then begin
257257 IDS_ABOUT:=' Î ïðîãðàììå...' ;
@@ -300,52 +300,54 @@ procedure TMain.IconMouse(var Msg: TMessage);
300300 case Msg.LParam of
301301 WM_LBUTTONDOWN:
302302 begin
303- if IsWindowVisible(Main.Handle) then
304- AppHide
305- else
306- AppShow;
303+ // Ñêðûâàåì PopupMenu, åñëè ïîêàçàí
304+ PostMessage(Handle, WM_LBUTTONDOWN, MK_LBUTTON, 0 );
305+ PostMessage(Handle, WM_LBUTTONUP, MK_LBUTTON, 0 );
307306 end ;
308307
308+ WM_LBUTTONDBLCLK:
309+ if IsWindowVisible(Handle) then AppHide else AppShow;
310+
309311 WM_RBUTTONDOWN:
310- PopupMenu .Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
312+ PopupMenuApp .Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
311313 end ;
312314end ;
313315
314- procedure TMain.WMActivate (var Msg: TMessage);
316+ { procedure TMain.WMActivate(var Msg: TMessage);
315317begin
316318 if (Msg.WParam = WA_INACTIVE) then
317319 AppHide;
318320 inherited;
319- end ;
321+ end;}
320322
321323procedure TMain.FormDestroy (Sender: TObject);
322324begin
323325 AllowClose:=true;
324326 AllowedIPs.Free;
325- Tray(3 );
327+ Tray(TrayDelete );
326328end ;
327329
328330procedure TMain.DefaultHandler (var Message);
329331begin
330332 if TMessage(Message).Msg = WM_TASKBARCREATED then
331- Tray(1 );
333+ Tray(TrayAdd );
332334 inherited ;
333335end ;
334336
335337procedure TMain.AppHide ;
336338begin
337339 AllowClose:=true;
338- ShowWindow(Handle, SW_HIDE);
340+ Tray(TrayAdd);
341+ ShowWindow(Main.Handle, SW_HIDE); // Ñêðûâàåì ïðîãðàììó
342+ ShowWindow(Application.Handle, SW_HIDE); // Ñêðûâàåì ñ ïàíåëè çàäà÷
339343end ;
340344
341345procedure TMain.AppShow ;
342346begin
343- if Main.AlphaBlend then begin
344- Main.AlphaBlendValue:=255 ;
345- Main.AlphaBlend:=false;
346- end ;
347- ShowWindow(Handle, SW_SHOW);
347+ ShowWindow(Main.Handle, SW_SHOW); // Ïîêàçûâàåì ïðîãðàììó
348+ ShowWindow(Application.Handle, SW_SHOW); // Ïîêàçûâàåì ïðîãðàììó íà ïàíåëè çàäà÷
348349 SetForegroundWindow(Handle);
350+ Tray(TrayDelete);
349351 AllowClose:=false;
350352end ;
351353
@@ -363,8 +365,8 @@ procedure TMain.CloseBtnClick(Sender: TObject);
363365
364366procedure TMain.AboutBtnClick (Sender: TObject);
365367begin
366- Application.MessageBox(PChar(Caption + ' 1.0' + #13 #10 +
367- IDS_LAST_UPDATE + ' 06.05 .25' + #13 #10 +
368+ Application.MessageBox(PChar(Caption + ' 1.0.2 ' + #13 #10 +
369+ IDS_LAST_UPDATE + ' 29.10 .25' + #13 #10 +
368370 ' https://r57zone.github.io' + #13 #10 +
369371 ' [email protected] ' ), PChar(IDS_ABOUT), MB_ICONINFORMATION);
370372end ;
@@ -392,7 +394,6 @@ procedure TMain.OkBtnClick(Sender: TObject);
392394 if IPSMemoChanged then
393395 AllowedIPsMemo.Lines.SaveToFile(ExtractFilePath(ParamStr(0 )) + ' AllowedIPs.txt' );
394396
395- // AppHide;
396397 IdHTTPServer.Active:=false;
397398 WinExec(PChar(ParamStr(0 )), SW_SHOW);
398399 AllowClose:=true;
@@ -414,4 +415,13 @@ procedure TMain.AllowedIPsMemoChange(Sender: TObject);
414415 IPSMemoChanged:=true;
415416end ;
416417
418+ procedure TMain.FormActivate (Sender: TObject);
419+ begin
420+ if Main.AlphaBlend then begin
421+ AppHide;
422+ Main.AlphaBlendValue:=255 ;
423+ Main.AlphaBlend:=false;
424+ end ;
425+ end ;
426+
417427end .
0 commit comments