AUTOIT:如何在win菜单中获取当前选择

时间:2013-07-08 09:36:08

标签: autoit

如何在菜单中获取当前所选项目?例如在记事本中。如何识别当前选择的是“字体...”

提前致谢!

ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("{DOWN}")

1 个答案:

答案 0 :(得分:7)

遍历菜单中的项目,查找突出显示的项目。对于子菜单,父项也将突出显示,因此您可以通过菜单递归:

#include <GUIMenu.au3>

ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("{DOWN}")

Sleep(100)

$hMenu = _GUICtrlMenu_GetMenu(WinGetHandle("Untitled - Notepad"))
MsgBox(0, "test", _GetSelected($hMenu))


Func _GetSelected($hMenu)
    Local $iItem = 0, $ret, $sub

    While 1
        Local $tInfo = _GUICtrlMenu_GetItemInfo($hMenu, $iItem, True)
        If @error Or Not @extended Then ExitLoop

        If BitAND(DllStructGetData($tInfo, "State"), $MFS_HILITE) Then
            $sub = DllStructGetData($tInfo, "SubMenu")

            If $sub Then
                $ret = _GetSelected($sub)

                If $ret <> "" Then Return $iItem & "-" & $ret
            EndIf

            Return $iItem
        EndIf

        $iItem += 1
    WEnd

    Return ""
EndFunc   ;==>_GetSelected