Author: Christian Cristofori
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
Commanderhttp://www.ghisler.com/ is doing...
Answer:
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:
1 2 procedure TfrmMain.tiIconClick(Sender: TObject; Button: TMouseButton;
3 Shift: TShiftState; X, Y: Integer);
4 var5 I: HMenu;
6 begin7 I := GetSystemMenu(Handle, False);
8 TrackPopupMenuEx(I, TPM_HORIZONTAL, X, Y, Handle, nil);
9 end;
Be warned: you must specify X and Y as screen coordinates, not relative to the icon, like some components do.