API函数 ModifyMenu来实现,完成对已存在菜单中的菜单项设置的改变。函数:
BOOL ModifyMenu(HMENU hMnu,UINT uPosition,UINT uFlags,UINT uIDNewItem, LPCTSTR lpNewItem);设计一个菜单,包括两个菜单项,其Caption属性分别设置为&File和&Help。事件代码:
procedure TForm1.Form1Create(Sender: TObject);
begin
ModifyMenu(MainMenu1.Handle,1,mf_BYPosition or mf_Popup or mf_Help,Help1.Handle,'帮助(&H)');
end;---------------//以下是DFM:
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = MainMenu1
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 216
Top = 16
object File1: TMenuItem
Caption = 'File'
end
object Help1: TMenuItem
Caption = 'Help'
object About1: TMenuItem
Caption = 'About'
end
end
end
end
BOOL ModifyMenu(HMENU hMnu,UINT uPosition,UINT uFlags,UINT uIDNewItem, LPCTSTR lpNewItem);设计一个菜单,包括两个菜单项,其Caption属性分别设置为&File和&Help。事件代码:
procedure TForm1.Form1Create(Sender: TObject);
begin
ModifyMenu(MainMenu1.Handle,1,mf_BYPosition or mf_Popup or mf_Help,Help1.Handle,'帮助(&H)');
end;---------------//以下是DFM:
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = MainMenu1
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object MainMenu1: TMainMenu
Left = 216
Top = 16
object File1: TMenuItem
Caption = 'File'
end
object Help1: TMenuItem
Caption = 'Help'
object About1: TMenuItem
Caption = 'About'
end
end
end
end
补充: 参数 mf_Help 决定菜单项位于窗口的最右端
MF_HELP
我在MSDN没有找到,它在哪里定义的
还是我的MSDN太老了
可能使用得到菜单 API 函数有
AppendMenu
ChangeMenu
InsertMenu
ModifyMenu
RemoveMenu
等
用ControlBar和ToolBar组合实现