How do I add a custom item to the system menu of my application?
The following example demonstrates using the Windows API function AppendMenu() to append a new menu item to the system menu. We will define a new system command constant : SC_MyMenuItem that will be used to identify our new item to the system. After adding the menu item, we will trap the WM_SYSCOMMAND message to test if our new menu item was selected.
Example:
type
TForm = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure WMSysCommand(var Msg: TWMSysCommand);
message WM_SYSCOMMAND;
public
{ Public declarations }
end;
var
Form : TForm ;
implementation
{$R *.DFM}
const
SC_MyMenuItem = WM_USER + ;procedure TForm .FormCreate(Sender: TObject);
begin
AppendMenu(GetSystemMenu(Handle, FALSE), MF_SEPARATOR, 0, '');
AppendMenu(GetSystemMenu(Handle, FALSE),
MF_STRING,
SC_MyMenuItem,
'My Menu Item');
end;
procedure TForm .WMSysCommand(var Msg: TWMSysCommand);
begin
if Msg.CmdType = SC_MyMenuItem then
ShowMessage('Got the message') else
inherited;
end;