Mega Code Archive

 
Categories / Delphi / System
 

Add your own entry in a windows system menu

To add your own entry in a window's system menu, you need to follow these steps: define an id that identifies your new menu item. This should be a number larger than the regular SC_xxxx constants. (idMyFunc = $f200) add the menu item, for example during the FormCreate event. Use your new identifier idMyFunc. 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;