Title: Add a new menu entry in the system menu
Question: How can I add a new entry in the system menu ?
Answer:
Ever wanted to add a menu entry to your form's system menu (the menu which appears when
you right click the form caption)
well here you go..
(this is only an example on how to implement this idea)
// declare this in the private section for your form:
procedure WMSYSCOMMAND(var message: Tmessage) ;message WM_SYSCOMMAND;
...
var
Form1: TForm1;
tempMenuitem : TmenuItem;
MenuItemHandle: THandle;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
MenuHandle : Thandle;
ReturnValue : boolean;
begin
tempMenuitem := TmenuItem.Create(self);
// Now hold the handle for the new inseted menu item
MenuItemHandle := tempMenuitem.Handle;
tempMenuitem.Caption := 'About..';
MenuHandle := GetSystemMenu ( handle , FALSE ) ;
ReturnValue := InsertMenu ( MenuHandle, 9, MF_BYPOSITION + MF_SEPARATOR, MenuItemHandle
,pchar(tempMenuitem.Caption) );
ReturnValue := InsertMenu ( MenuHandle, 10, MF_BYPOSITION + MF_STRING , MenuItemHandle
,pchar(tempMenuitem.Caption) );
DrawMenuBar(handle);
end;
procedure TForm1.WMSYSCOMMAND(var message: Tmessage) ;
begin
If ( message.WParam = MenuItemHandle ) then
ShowMessage('About click');
inherited; //
end;
...
// NOTE: This code was tested on delphi 4, Windows NT workstation 4