Mega Code Archive

 
Categories / Delphi / Graphic
 

System menu in trayicon mode

Title: System menu in trayicon mode Question: 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. 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 warner: you must specify X and Y as screen coordinates, not relative to the icon, like some components do.