Adding a custom menu item to the form's system menu
Here's a bit of code to show you how to add your own custom menu items to your form's system menu (the icon on the top left corner of your form during runtime). See the comments for code you need to add to your form.
procedure AddSystemMenuItem(Menu: hMenu; Caption: string; id: UINT);
{ Adds menu items to the system menu handle. }
(* Usage:
private
procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
begin
{ Be sure you are using the correct CmpType as you assigned }
{ in your AddMenuItem() calls. }
if Message.CmdType = 1 then
ShowMessage('Hello, World!')
else
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
MenuHandle: THandle;
begin
MenuHandle := GetSystemMenu(Handle, False);
AddSystemMenuItem(MenuHandle, '-', 0);
AddSystemMenuItem(MenuHandle, '&Hello, World!', 1);
end;
*) var
mii: TMenuItemInfo;
begin
mii.fMask := MIIM_ID or MIIM_TYPE or MIIM_DATA;
if Caption = '-' then
mii.fType := MFT_SEPARATOR
else
mii.fType := MFT_STRING;
mii.wID := id;
mii.dwTypeData := PChar(Caption);
mii.cbSize := SizeOf(TMenuItemInfo);
InsertMenuItem(Menu, GetMenuItemCount(Menu), TRUE, mii);
end;