添加新菜单项到菜单末尾
#Include <GuiMenu.au3>
_GUICtrlMenu_AddMenuItem($hMenu, $sText[, $iCmdID = 0[, $hSubMenu = 0]])
$hMenu | 菜单句柄 |
$sText | 菜单项的文本.如为空白,将添加一个分隔. |
$iCmdID | [可选参数] 分配给该项目的命令 ID |
$hSubMenu | [可选参数] 与菜单项关联的子菜单句柄 |
成功: | 菜单项的 0 基索引 |
失败: | 返回 -1 |
#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
_Main()
Func _Main()
Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
Local Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout
; 创建 GUI
$hGUI = GUICreate("Menu", 400, 300)
; Create File menu
$hFile = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_AddMenuItem($hFile, "&New", $idNew)
_GUICtrlMenu_AddMenuItem($hFile, "&Open", $idOpen)
_GUICtrlMenu_AddMenuItem($hFile, "&Save", $idSave)
_GUICtrlMenu_AddMenuItem($hFile, "", 0)
_GUICtrlMenu_AddMenuItem($hFile, "E&xit", $idExit)
; Create Edit menu
$hEdit = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_AddMenuItem($hEdit, "&Cut", $idCut)
_GUICtrlMenu_AddMenuItem($hEdit, "C&opy", $idCopy)
_GUICtrlMenu_AddMenuItem($hEdit, "&Paste", $idPaste)
; Create Help menu
$hHelp = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_AddMenuItem($hHelp, "&About", $idAbout)
; Create Main menu
$hMain = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_AddMenuItem($hMain, "&File", 0, $hFile)
_GUICtrlMenu_AddMenuItem($hMain, "&Edit", 0, $hEdit)
_GUICtrlMenu_AddMenuItem($hMain, "&Help", 0, $hHelp)
; Set window menu
_GUICtrlMenu_SetMenu($hGUI, $hMain)
GUISetState()
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main