函数参考


_GUICtrlMenu_AppendMenu

追加一个新项目到指定菜单栏,下拉菜单,子菜单或快捷菜单的末尾,

#Include <GuiMenu.au3>
_GUICtrlMenu_AppendMenu($hMenu, $iFlags, $iNewItem, $pNewItem)

参数

$hMenu 菜单句柄
$iFlags Specifies flags to control the appearance and behavior of the new menu item:
$MF_BITMAP - Uses a bitmap as the menu item
$MF_CHECKED - Places a check mark next to the menu item. If the application provides check-mark bitmaps,
this flag displays the check-mark bitmap next to the menu item.
$MF_DISABLED - Disables the menu item so that it cannot be selected, but the flag does not gray it.
$MF_ENABLED - Enables the menu item so that it can be selected, and restores it from its grayed state.
$MF_GRAYED - Disables the menu item and grays it so that it cannot be selected.
$MF_MENUBARBREAK - Functions the same as $MF_MENUBREAK for a menu bar. For a drop down menu, submenu, or
shortcut menu, the new column is separated from the old column by a vertical line.
$MF_MENUBREAK - Places the item on a new line (for a menu bar) or in a new column (for a drop down menu,
submenu, or shortcut menu) without separating columns.
$MF_OWNERDRAW - Specifies that the item is an owner drawn item. Before the menu is displayed for the first
time, the window that owns the menu receives a $WM_MEASUREITEM message to retrieve the width and height of
the menu item. The $WM_DRAWITEM message is then sent to the window procedure of the owner window whenever the
appearance of the menu item must be updated.
$MF_POPUP - Specifies that the menu item opens a drop down menu or submenu. The iNewItem parameter
specifies a handle to the drop down menu or submenu. This flag is used to add a menu name to a menu bar, or a
menu item that opens a submenu to a drop down menu, submenu, or shortcut menu.
$MF_SEPARATOR - Draws a horizontal dividing line. This flag is used only in a drop down menu, submenu, or
shortcut menu. The line cannot be grayed, disabled, or highlighted. The pNewItem and iNewItem parameters are
ignored.
$MF_STRING - Specifies that the menu item is a text string. The pNewItem parameter is a string.
$MF_UNCHECKED - Does not place a check mark next to the item. If the application supplies check mark
bitmaps, this flag displays the clear bitmap next to the menu item.
$iNewItem 指定任一新菜单项的标识符,如果 $iFlags 参数设置为一个弹出式菜单,
则指定下拉菜单或子菜单句柄.
$pNewItem 指定新菜单项的内容.该参数设置内容的解释取决于
$iFlags 参数是否包括 $MF_BITMAP, $MF_OWNERDRAW, 或 $MF_STRING 标志:
$MF_BITMAP - 包含一个位图句柄
$MF_OWNERDRAW - 包含应用程序提供的值,可用于维护相关菜单项的其他数据
当 $WM_MEASUREITEM or $WM_DRAWITEM 消息发送菜单创建或更新其外观时,
该值所在结构的 ItemData 成员指向 lParam 参数.
$MF_STRING - 包含字符串

返回值

成功: 返回 True
失败: 返回 False

注意/说明

None.

相关

_GUICtrlMenu_InsertMenuItem

详情参考

在MSDN中搜索


示例/演示


#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_InsertMenuItem($hFile, 0, "&New", $idNew)
    _GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $idSave)
    _GUICtrlMenu_InsertMenuItem($hFile, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem($hFile, 4, "E&xit", $idExit)

    ; Create Edit menu
    $hEdit = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $idCut)
    _GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $idCopy)
    _GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $idPaste)

    ; Create Help menu
    $hHelp = _GUICtrlMenu_CreateMenu()

    ; Create Main menu
    $hMain = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile)
    _GUICtrlMenu_InsertMenuItem($hMain, 1, "&Edit", 0, $hEdit)
    _GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp)

    ; Set window menu
    _GUICtrlMenu_SetMenu($hGUI, $hMain)
    GUISetState()

    ; Add About menu item
    _GUICtrlMenu_AppendMenu($hHelp, $MF_STRING, $idAbout, "&About")

    ; 循环直到用户退出
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main