图1 添加组件后的窗体 |
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; |
unit Unit1; interface uses SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls; type TForm1 = class(TForm) MainMenu1: TMainMenu; File1: TMenuItem; Exit1: TMenuItem; procedure Exit1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public procedure WMSysCommand(var Msg:TWMSysCommand);message WM_SysCommand; end; var Form1: TForm1; implementation {$R *.DFM} 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; 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; end. |
图2 程序运行结果 |