; ifnot (csDesigning in ComponentState) then Shell_NotifyIcon(Nim_Delete, @fData); inherited Destroy; end;
{ Whenever any information changes, update the system tray. } procedure TTrayIcon.Changed; begin ifnot (csDesigning in ComponentState) then Shell_NotifyIcon(NIM_MODIFY, @fData); end;
{ When the Application is minimized, minimize to the system tray.} procedure TTrayIcon.AppMinimize(Sender: TObject); begin Minimize end;
{ When restoring from the system tray, restore the application. } procedure TTrayIcon.AppRestore(Sender: TObject); begin Restore end;
{ Message handler for the hidden shell notification window. Most messages use Wm_Callback_Message as the Msg ID, with WParam as the ID of the shell notify icon data. LParam is a message ID for the actual message, e.g., Wm_MouseMove. Another important message is Wm_EndSession, telling the shell notify icon to delete itself, so Windows can shut down.
Send the usual Delphi events for the mouse messages. Also interpolate the OnClick event when the user clicks the left button, and popup the menu, if there is one, for right click events. }
procedure TTrayIcon.OnMessage(var Msg: TMessage); { Return the state of the shift keys. } function ShiftState: TShiftState; begin Result := []; if GetKeyState(VK_SHIFT) < 0 then Include(Result, ssShift); if GetKeyState(VK_CONTROL) < 0 then Include(Result, ssCtrl); if GetKeyState(VK_MENU) < 0 then Include(Result, ssAlt); end; var Pt: TPoint; Shift: TShiftState; begin case Msg.Msg of Wm_QueryEndSession: Msg.Result := 1; Wm_EndSession: if TWmEndSession(Msg).EndSession then EndSession; Wm_Callback_Message: case Msg.lParam of WM_MOUSEMOVE: begin Shift := ShiftState; GetCursorPos(Pt); DoMouseMove(Shift, Pt.X, Pt.Y); end; WM_LBUTTONDOWN: begin Shift := ShiftState + [ssLeft]; GetCursorPos(Pt); DoMouseDown(mbLeft, Shift, Pt.X, Pt.Y); fClicked := True; end; WM_LBUTTONUP: begin Shift := ShiftState + [ssLeft]; GetCursorPos(Pt); if fClicked then begin fClicked := False; Click; end; DoMouseUp(mbLeft, Shift, Pt.X, Pt.Y); end; WM_LBUTTONDBLCLK: DblClick; WM_RBUTTONDOWN: begin Shift := ShiftState + [ssRight]; GetCursorPos(Pt); DoMouseDown(mbRight, Shift, Pt.X, Pt.Y); DoMenu; end; WM_RBUTTONUP: begin Shift := ShiftState + [ssRight]; GetCursorPos(Pt); DoMouseUp(mbRight, Shift, Pt.X, Pt.Y); end; WM_RBUTTONDBLCLK: &