使用API动态添加删除菜单项
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;type
TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject);private { Private declarations } hMenu,hPopMenu1,hPopMenu2:HMENU;public { Public declarations }end;
var
Form1: TForm1;implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
beginhMenu:=CreateMenu();hPopMenu1:=CreateMenu();hPopMenu2:=CreateMenu();AppendMenu(hPopMenu1,MF_STRING,40001,'New');AppendMenu(hPopMenu1,MF_STRING,40002,'Open');AppendMenu(hPopMenu2,MF_STRING,40005,'About');AppendMenu(hPopMenu1,MF_POPUP, hPopMenu2, 'Help');AppendMenu(hMenu,MF_POPUP,hPopMenu1,'&File');SetMenu(self.Handle,hMenu);end;procedure TForm1.Button1Click(Sender: TObject);beginDeleteMenu(hPopMenu1,2,MF_BYPOSITION);end;end.