fIcon := TIcon.Create;
fIcon.Assign(Application.Icon);
if not (csDesigning in ComponentState) then
begin
FillChar(fData, SizeOf(fData), 0);
fData.cbSize := SizeOf(fData);
fData.Wnd := AllocateHwnd(OnMessage); //
handle to get notification message
fData.hIcon := Icon.Handle; // icon to display
StrPLCopy(fData.szTip, Application.Title, SizeOf(fData.szTip) - 1);
fData.uFlags := Nif_Icon or Nif_Message;
if Application.Title <> '' then
fData.uFlags := fData.uFlags or Nif_Tip;
fData.uCallbackMessage := WM_CALLBACK_MESSAGE;
if not Shell_NotifyIcon(NIM_ADD, @fData) then // add it
raise EOutOfResources.Create('Cannot create shell notification icon');
{
Replace the application's minimize and restore handlers with
special ones for the tray. The TrayIcon component has its own
OnMinimize and OnRestore events that the user can set.
}
Application.OnMinimize := AppMinimize;
Application.OnRestore := AppRestore;
end;