System menu in tray-icon mode (Views: 103)
I always wanted to show the Main window's system menu also when the only thing the user could click on the screen of my application, was the tray icon. Like Total Commander is doing...
With the most components provinding very-easy-to-use icon tray support, you can specify to show up a popupmenu, or you can catch the click event.
But you can't easily show the same menu as if you right-clicked on application's taskbar icon.
Just catch the WM_CLICK event over the icon, or simply use the OnClick event as shown:
procedure TfrmMain.tiIconClick(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
I := GetSystemMenu(Handle, False);
TrackPopupMenuEx(I, TPM_HORIZONTAL, X, Y, Handle, nil);
Be warned: you must specify X and Y as screen coordinates, not relative to the icon, like some components do.
<< Back to main page