如果截获一个窗体MainMenu菜单下子菜单的单击操作
用autoinfo无法获取到菜单的信息,怎么才能截获呢。望高手指点。 囧 。。。。不知道咋说。。。寥寥数语。。。 囧 。。。。不知道咋说。。。寥寥数语。。。 #include <GUIConstantsEx.au3>#include <StaticConstants.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $defaultstatus = "就绪", $status, $filemenu, $fileitem
Local $helpmenu, $saveitem, $infoitem, $exititem, $recentfilesmenu
Local $separator1, $viewmenu, $viewstatusitem, $okbutton, $cancelbutton
Local $statuslabel, $msg, $file
GUICreate("我的菜单窗口", 300, 200)
$filemenu = GUICtrlCreateMenu("文件(&F)")
$fileitem = GUICtrlCreateMenuItem("打开", $filemenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu("帮助")
$saveitem = GUICtrlCreateMenuItem("保存", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$infoitem = GUICtrlCreateMenuItem("信息", $helpmenu)
$exititem = GUICtrlCreateMenuItem("退出", $filemenu)
$recentfilesmenu = GUICtrlCreateMenu("最近文件", $filemenu, 1)
$separator1 = GUICtrlCreateMenuItem("", $filemenu, 2) ; 创建分隔行
$viewmenu = GUICtrlCreateMenu("查看", -1, 1) ; 创建 "帮助" 的前项菜单
$viewstatusitem = GUICtrlCreateMenuItem("状态栏", $viewmenu)
GUICtrlSetState(-1, $GUI_CHECKED)
$okbutton = GUICtrlCreateButton("确定", 50, 130, 70, 20)
GUICtrlSetState(-1, $GUI_FOCUS)
$cancelbutton = GUICtrlCreateButton("删除", 180, 130, 70, 20)
$statuslabel = GUICtrlCreateLabel($defaultstatus, 0, 165, 300, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $fileitem Then
$file = FileOpenDialog("选择文件...", @TempDir, "全部 (*.*)")
If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu)
EndIf
If $msg = $viewstatusitem Then
If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
GUICtrlSetState($statuslabel, $GUI_HIDE)
Else
GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
GUICtrlSetState($statuslabel, $GUI_SHOW)
EndIf
EndIf
If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop
If $msg = $infoitem Then MsgBox(0, "信息", "只是测试...")
WEnd
GUIDelete()
EndFunc ;==>Example 外部窗口,可以参考这个帮助示例
#include <GuiMenu.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $hWnd, $hMain, $hFile
; Open Notepad
Run("Notepad.exe")
WinWaitActive("")
$hWnd = WinGetHandle("")
$hMain = _GUICtrlMenu_GetMenu($hWnd)
$hFile = _GUICtrlMenu_GetItemSubMenu($hMain, 0)
; Get/Set Open item text
Writeln("Open item text: " & _GUICtrlMenu_GetItemText($hFile, 1))
_GUICtrlMenu_SetItemText($hFile, 1, "&Closed")
Writeln("Open item text: " & _GUICtrlMenu_GetItemText($hFile, 1))
EndFunc ;==>_Main
; Write a line of text to Notepad
Func Writeln($sText)
ControlSend("", "", "Edit1", $sText & @CR)
EndFunc ;==>Writeln 回复 5# 风行者
谢谢 您的思路对于解决我的问题很多有帮助!
页:
[1]