Scalabium Software

SMReport Autogenerated
Knowledge for your independence'.
Home Delphi and C++Builder tips


#155: To show the system menu

As you know, every form/window in MS Windows (TForm in VCL terms) have a system menu. Usually there are pre-defined items like Close, Mimimize, Maximize, Move etc

But, of course, you also may add any own item in this system menu (see my tip#30 for sample)

So sometimes you may want to show this system menu for form but in any own position and from any your event. For example, user'll click on some your button and will see this system menu:

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


Published: July 28, 2002

See also
 
Viewer for TNEF-files (winmail.dat)
Excel Web-stream
Paradox to Text converter
Protected Storage Viewer
DBISAM Viewer
ABA Picture Convert
Viewer for MS Outlook Messages
ABA Spreadsheet Convert
Database Information Manager
ABA Database Convert
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2017, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising