delphi
编程技巧
源代码在线查看: 把窗体的系统菜单添加到窗体的菜单条上.txt
把窗体的系统菜单添加到窗体的菜单条上 (2001年5月22日)
本站更新 分类:系统 作者: 推荐: 阅读次数:123
(http://www.codesky.net)
--------------------------------------------------------------------------------
把窗体的系统菜单添加到窗体的菜单条上
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 );
end;
End;
end;
procedure TForm1.SystemMenuClick(Sender: TObject);
begin
With Sender As TMenuitem do
Self.perform( WM_SYSCOMMAND, Tag, 0 );
end;