Class inheritance or modify Tform source code directly from the window, to dynamically generate a reinstall again, as if also not convenient,
Const
WM_BARICON=WM_USER + 200;
Procedure TForm1. WMSysCommand (var Message: TMessage);
Var
LpData: PNotifyIconData;
The begin
If the Message. The WParam=SC_ICON then/news/SC_ICON equal to minimize
The begin
//if the user to minimize the window, the window hidden and add an icon on the taskbar
LpData:=new (PNotifyIconDataA);
LpData. CbSize:=88;
//SizeOf (PNotifyIconDataA);
LpData. Wnd:=Form1. Handle;
LpData. HIcon:=Form1. Icon. Handle;
LpData. UCallbackMessage:=WM_BARICON;
LpData. : uID=0;
Strcopy (@ lpData szTip, pchar (form1. Caption));
LpData. UFlags:=NIF_ICON the or NIF_MESSAGE or NIF_TIP;
Shell_NotifyIcon (NIM_ADD lpData);
The dispose (lpData);
Form1. Visible:=False;
End
The else
The begin
//if it is other SystemCommand news call system default processing function processing,
DefWindowProc (Form1. Handle the Message. The Msg, Message. The WParam, Message. The LParam);
end;
end;
Procedure TForm1. WMBarIcon (var Message: TMessage);
Var
LpData: PNotifyIconData;
The begin
If (Message. LParam=WM_LBUTTONDOWN) then
The begin
//if the user clicks on the task bar icon icon will be deleted and reply window,
LpData:=new (PNotifyIconDataA);
LpData. Wnd:=Form1. Handle;
LpData. HIcon:=Form1. Icon. Handle;
Shell_NotifyIcon (NIM_DELETE lpData);
The dispose (lpData);
Form1. Visible:=True;
end;
end;
CodePudding user response:
Already have such controls, but I can't think what, at the moment you check yourself, too little, too lazy to moveCodePudding user response:
Window to contract the Delphi program to the simplest method to realize the system tray- the uTrayIcon. The pas to join to your project, to realize the function of what you need, such is simple enough, right?