Mirror

System menu in tray-icon mode (Views: 103)


Problem/Question/Abstract:

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...

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:

procedure TfrmMain.tiIconClick(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  I: HMenu;
begin
  I := GetSystemMenu(Handle, False);
  TrackPopupMenuEx(I, TPM_HORIZONTAL, X, Y, Handle, nil);
end;

Be warned: you must specify X and Y as screen coordinates, not relative to the icon, like some components do.

<< Back to main page