Mega Code Archive

 
Categories / Delphi / Forms
 

How to show the system menu for form on demand

Title: How to show the system menu for form on demand procedure TForm1.Button1Click(Sender: TObject); var hMenuHandle: hMENU; hMenuItem: DWORD; p: TPoint; begin {recalculate button coordinates to screen coordinates} p.X := Button1.Left; p.Y := Button1.Top; p := Button4.ClientToScreen(p); hMenuHandle := GetSystemMenu(Handle, False); hMenuItem := Longword(Windows.TrackPopupMenu(hMenuHandle, TPM_LEFTBUTTON or TPM_RIGHTBUTTON or TPM_RETURNCMD, p.X, p.Y, 0, Handle, nil)); if hMenuItem 0 then SendMessage(Handle, WM_SYSCOMMAND, hMenuItem, 0); end; This could be really useful if you replace standard caption and draw own ??header??. Generally better for this task to process the WM_NCPAINT and WM_NCHITTEST messages but I saw a few implementations without these messages too...