Title: add items to the Application's Windows System Menu?
private
procedure OnMessageHandler(var Msg: TMsg; var Handled: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// Identifiers of the new menu items
// Konstanten, welche einen Menüpunkt eindeutig identifizieren
const
SC_MyMenuItem1 = WM_USER + $101;
SC_MyMenuItem2 = WM_USER + $102;
procedure TForm1.FormCreate(Sender: TObject);
var
hSysMenu: THandle;
begin
// Get Systemmenu Handle
// Handle zum Systemmenü ermitteln
hSysMenu := GetSystemMenu(Application.Handle, False);
// Add own menu items
// Eigene Menüitems einfügen
AppendMenu(hSysMenu, MF_SEPARATOR, 0, #0);
AppendMenu(hSysMenu, MF_STRING, SC_MyMenuItem1, '&My Menuitem 1');
AppendMenu(hSysMenu, MF_STRING or MF_CHECKED , SC_MyMenuItem2, '&My Menuitem 2');
// Assign a own OnMessage event handler
// OnMessage event handler festlegen
Application.OnMessage := OnMessageHandler;
end;
// OnMessage event handler
procedure TForm1.OnMessageHandler;
begin
if Msg.message = WM_SYSCOMMAND then
begin
case Msg.wParam of
// Which item selected?
// Welches Menitem wurde ausgewählt?
SC_MyMenuItem1:
begin
ShowMessage('SC_MyMenuItem1');
Handled := True;
end;
SC_MyMenuItem2:
begin
ShowMessage('SC_MyMenuItem2');
Handled := True;
end;
end;
end;
end;