给你一个例子,里面虽然没有 insertMenu ,但是一些主要参数的用法
都有了。你可以参照下面用到的和菜单有关的API。
把窗体的系统菜单添加到窗体的菜单条上
procedure TForm1.Button3Click(Sender: TObject);
var
item: TMenuItem;
sysmenuHandle: HMENU;
i, itemcount: Integer;
buffer: array [0..128] of Char;
itemID: Integer;
itemflags: DWORD;
begin
//handleNeeded;
//得到系统菜单的handle
sysmenuHandle := GetSystemMenu( handle, false );
If sysmenuHandle <> 0 Then
Begin
//得到系统菜单的个数
itemcount := GetMenuItemcount( sysmenuHandle );
for i:= 0 to itemcount - 1 do
begin
//得到指定菜单项的当前状态
itemflags := GetMenuState
(sysmenuhandle, i, MF_BYPOSITION );
//如果是横线
If (itemflags and MF_SEPARATOR) = MF_SEPARATOR
Then
item := NewLine
Else Begin
//得到指定菜单项的Caption
GetMenuString( sysmenuhandle, i, buffer,
sizeof(buffer),MF_BYPOSITION );
//得到指定菜单的在系统菜单中的ID
itemID := GetMenuItemID( sysmenuhandle, i );
//创建新的MenuItem
item := NewItem( buffer, 0,
(itemflags and MF_CHECKED) = MF_CHECKED,
(itemflags and (MF_DISABLED or MF_GRAYED)) = 0,
SystemMenuClick,0,
format('Sysmenu_%d',[itemid]));
item.tag := itemID;
End;
systemmenu.Add( item );
// sysemnu为主菜单上的一个TMenuItem
end;
End;
end;
procedure TForm1.SystemMenuClick(Sender: TObject);
begin
With Sender As TMenuitem do
Self.perform(WM_SYSCOMMAND, Tag, 0 );
end;