我工作的一个项目,我决定我应该有史以前搜索过的东西(因为它是与您可以搜索东西的应用程序),所以我一直在想我可以只创建上下文菜单或常规菜单中,我能以某种方式强制激活点击一个按钮或使用加速器。
现在,我一直无法弄清楚如何使这项工作。
首先,我尝试了GuiCtrlSetState()
功能,这似乎并没有工作(我试过表演和对焦),那么我想加速器和他们没有做任何事情。
那么,我基本上试图做的是某种弹出的,你点击一个按钮或按下一键触发的上下文菜单或常规菜单打开。
我知道我可能是老同学,并使用新的GUI或只是一个组合框的历史或什么,但我还挺想这样,如果有任何的方式来做到这一点。
#NoTrayIcon
#include <GUIConstantsEx.au3>
GUICreate("test123")
$but = guictrlcreatebutton("test", -1, -1, -1)
$xt = GUICtrlCreateContextMenu("test context menu")
GUICtrlCreateMenuItem("test1", $xt)
GUICtrlCreateMenuItem("test2", $xt)
GUISetState(@SW_MAXIMIZE)
While 1
$msg = GUIGetMsg()
If $msg = $but Then
GUICtrlSetState($xt, $GUI_FOCUS)
EndIf
Sleep(5)
WEnd
如果您检查GUICtrlCreateContextMenu下的帮助文件:
; right click on gui to bring up context Menu.
; right click on the "ok" button to bring up a controll specific context menu.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
GUICreate("My GUI Context Menu", 300, 200)
Local $idContextmenu = GUICtrlCreateContextMenu()
Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu)
Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)
Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20)
Local $idButtoncontext = GUICtrlCreateContextMenu($idButton)
Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext)
Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
GUICtrlCreateMenuItem("", $idContextmenu) ; separator
Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
GUISetState(@SW_SHOW)
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idButton
MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK')
Case $idMenuAbout
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About')
Case $idMenuOpen
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open')
Case $idMenuSave
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save')
Case $idMenuInfo
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info')
Case $idNewsubmenuText
MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text')
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Example