unit Unit1;
interface
uses
SysUtils, Windows, Messages,Dialogs, Menus, Controls, StdCtrls, Classes,forms,ShellAPI;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
file1: TMenuItem;
exit1: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure exit1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMSysCommand (var Msg: TWMSysCommand);message WM_SysCommand;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
I:Integer;
begin
AppendMenu(GetSystemMenu(Handle,False),MF_SEPARATOR,0,'');
with MainMenu1 do
begin
for I := 0 to Items.Count - 1 do
AppendMenu(GetSystemMenu(self.Handle,FALSE),mf_Popup,
Items[I].Handle,PAnsiChar(Items[I].Caption));
end;
end;
procedure TForm1.WMSysCommand (var Msg: TWMSysCommand);
var
Item: TMenuItem;
begin
Item := MainMenu1.FindItem(Msg.CmdType, fkCommand);
if Item <> nil then
Item.Click;
inherited;
end;
procedure TForm1.exit1Click(Sender: TObject);
begin
Close;
end;
end.
//运行效果如下图: