[已解决]弹出式菜单打开另一个GUI的问题
本帖最后由 bsbq 于 2013-1-30 23:12 编辑我期望的功能描述:点击鼠标右键,弹出菜单,选择菜单项Open,打开另一个GUI界面操作
代码是帮助中2个例子的合成,但打开Example后,就死循环。
我的判断是问题出在有2个消息循环,但不知如何解决#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global Enum $idOpen = 1000, $idSave, $idInfo
_Main()
Func _Main()
; Create GUI
GUICreate("Menu", 400, 300)
GUISetState()
; Register message handlers
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; Handle WM_COMMAND messages
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $ilParam
Switch $iwParam
Case $idOpen
Example()
Case $idSave
_WinAPI_ShowMsg("Save")
Case $idInfo
_WinAPI_ShowMsg("Info")
EndSwitch
EndFunc ;==>WM_COMMAND
; Handle WM_CONTEXTMENU messages
Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $ilParam
Local $hMenu
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $idInfo)
_GUICtrlMenu_TrackPopupMenu($hMenu, $iwParam)
_GUICtrlMenu_DestroyMenu($hMenu)
Return True
EndFunc ;==>WM_CONTEXTMENU
Func Example()
Local $radio1, $radio2, $msg
GUICreate("My GUI radio") ; will create a dialog box that when displayed is centered
$radio1 = GUICtrlCreateRadio("Radio 1", 10, 10, 120, 20)
$radio2 = GUICtrlCreateRadio("Radio 2", 10, 40, 120, 20)
GUICtrlSetState($radio2, $GUI_CHECKED)
GUISetState() ; will display andialog box with 1 checkbox
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
MsgBox(64, 'Info:', 'You clicked the Radio 1 and it is Checked.')
Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
MsgBox(64, 'Info:', 'You clicked on Radio 2 and it is Checked.')
EndSelect
WEnd
EndFunc ;==>Example
多窗口用消息模式比较好 路过。。。。。 仔细读了帮助中GUI Reference
对于多窗口MessageLoop mode和OnEvent mode都可以实现
算是解决了吧 用消息的话,在lz这个代码中要指定$hwnd,切换对应窗体句柄才行
页:
[1]