DelphiFAQ Home Search:
General :: Windows :: Programming :: Windows with Delphi :: Windows Forms
Code snippets, Q+A around the Windows user interface. From a Delphi perspective, but usually applicable to other languages.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

Add your own entry in a window's system menu

To add your own entry in a window's system menu, you need to follow these steps:


  1. define an id that identifies your new menu item. This should be a number larger than the regular SC_xxxx constants. (idMyFunc = $f200)
  2. add the menu item, for example during the FormCreate event. Use your new identifier idMyFunc.
  3. add some code in the WMSysCommand handler that checks for your menu event and put in your desired code


Use the following code as a basis:

type
   TForm1 = class(TForm);
   // ..
  private
     procedure WMSysCommand(var message: TWMSysCommand);
       message WM_SYSCOMMAND;
   // ..
  end;
 
 implementation
 
 const
   idMyFunc = $f200;
 
 procedure TForm1.WMSysCommand(var message: TWMSysCommand);
 begin
   inherited;
   if message.CmdType and $FFF0 = idMyFunc then
     ShowMessage('my new function');
 end;
 
 procedure TForm1.FormCreate(Sender: TObject);
 begin
   AppendMenu(GetSystemMenu(Handle, False), MF_STRING, idMyFunc, 'Info');
 end;