函数参考


_GUICtrlMenu_GetMenu

返回指定窗口的菜单句柄.

#Include <GuiMenu.au3>
_GUICtrlMenu_GetMenu($hWnd)

参数

$hWnd 检索菜单句柄的窗口标识符

返回值

成功: 返回目标窗口菜单句柄
失败: 返回 0

注意/说明

 本函数对于浮动菜单栏没有作用.
 浮动菜单栏是自定义模仿标准菜单的控件,但不菜单

相关

_GUICtrlMenu_SetMenu, _GUICtrlMenu_FindParent

详情参考

在MSDN中搜索


示例/演示


#include <GuiMenu.au3>

_Main()

Func _Main()
    Local $hWnd, $hMain, $hItem1, $hItem2

    ; 打开记事本
    Run("notepad.exe")
    WinWaitActive("[CLASS:Notepad]")
    $hWnd = WinGetHandle("[CLASS:Notepad]")
    $hMain = _GUICtrlMenu_GetMenu($hWnd)

    ; Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem1, 0, "SubItem &1", 0x1000)
    _GUICtrlMenu_InsertMenuItem($hItem1, 1, "SubItem &2", 0x1001)

    ; Create menu
    $hItem2 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hItem2, 0, "Item &1", 0x2000, $hItem1)
    _GUICtrlMenu_InsertMenuItem($hItem2, 1, "Item &2", 0x2001)
    _GUICtrlMenu_InsertMenuItem($hItem2, 2, "", 0)
    _GUICtrlMenu_InsertMenuItem($hItem2, 3, "Item &3", 0x2002)
    _GUICtrlMenu_InsertMenuItem($hItem2, 4, "Item &4", 0x2003)

    ; Insert new menu into Notepad
    _GUICtrlMenu_InsertMenuItem($hMain, 6, "&AutoIt", 0, $hItem2)
    _GUICtrlMenu_DrawMenuBar($hWnd)

EndFunc   ;==>_Main