郁闷,关于OnEvent 模式的问题
在下面这个例子中,我要怎么实现对子窗口按钮的响应呢?帮我瞧瞧!
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
$main = GuiCreate("MyGUI", 340, 60,-1, -1 )
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
$Button_1 = GuiCtrlCreateButton("显示窗口1", 10, 10, 100, 40)
$Button_2 = GuiCtrlCreateButton("显示窗口2", 120, 10, 100, 40)
$Button_3 = GuiCtrlCreateButton("显示窗口3", 230, 10, 100, 40)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUICtrlSetOnEvent($Button_2, "gui")
GUICtrlSetOnEvent($Button_3, "gui")
GUICtrlSetOnEvent($Button_1, "gui")
While 1
;;;
WEnd
Exit
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Switch @GUI_WINHANDLE
Case $main
Exit
Case Else
GUIDelete(@GUI_WINHANDLE)
EndSwitch
Case $Button_2
if WinExists("子窗口2") = 0 Then
GuiCreate("子窗口2", 140, 60,10,100,-1,-1,$main)
$jjjj = GUICtrlCreateButton("454454", 5, 5, 100, 50)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
EndIf
Case $Button_3
if WinExists("子窗口3") = 0 Then
GuiCreate("子窗口3", 140, 60,160,100,-1,-1,$main)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
EndIf
Case $Button_1
if WinExists("子窗口1") = 0 Then
GuiCreate("子窗口1", 140, 60,300,100,-1,-1,$main)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
EndIf
EndSwitch
EndFunc ;==>gui
这个子窗口2中有个按钮~~~~~~~~~~~~~~~
[ 本帖最后由 破帽遮颜 于 2008-5-14 20:54 编辑 ] ...............子窗口没这么麻烦吧?看这个例子
#include <GUIConstants.au3>
#Region ### START Koda GUI section ### Form=
$AForm1 = GUICreate("AForm1", 324, 52, 216, 124)
$Button1 = GUICtrlCreateButton("1", 0, 0, 113, 49, 0)
$Button2 = GUICtrlCreateButton("显示子窗口", 216, 0, 105, 49, 0)
GUISetState(@SW_SHOW)
$AForm2 = GUICreate("AForm2", 303, 133, 593, 115)
$Button21 = GUICtrlCreateButton("确认", 112, 0, 105, 49, 0)
$Button22 = GUICtrlCreateButton("取消", 216, 0, 105, 49, 0)
;~ GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Switch $nMsg
Case $AForm1
Exit
Case $AForm2
GUISwitch($AForm2)
GUISetState(@SW_HIDE)
EndSwitch
Case $Button1
MsgBox(0, "你好", "你点了第一个按钮")
Case $Button2
GUISwitch($AForm2)
GUISetState(@SW_SHOW)
Case $Button21
MsgBox(0, "你好", "你点了子窗口第一个按钮")
Case $Button22
GUISwitch($AForm2)
GUISetState(@SW_HIDE)
EndSwitch
WEnd #include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
$main = GuiCreate("MyGUI", 340, 60,-1, -1 )
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
$Button_1 = GuiCtrlCreateButton("显示窗口1", 10, 10, 100, 40)
$Button_2 = GuiCtrlCreateButton("显示窗口2", 120, 10, 100, 40)
$Button_3 = GuiCtrlCreateButton("显示窗口3", 230, 10, 100, 40)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUICtrlSetOnEvent($Button_2, "gui")
GUICtrlSetOnEvent($Button_3, "gui")
GUICtrlSetOnEvent($Button_1, "gui")
While 1
;;;
WEnd
Exit
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Switch @GUI_WINHANDLE
Case $main
Exit
Case Else
GUIDelete(@GUI_WINHANDLE)
EndSwitch
Case $Button_2
if WinExists("子窗口2") = 0 Then
Opt("GUIOnEventMode", 0)
GuiCreate("子窗口2", 140, 60,10,100,-1,-1,$main)
$jjjj = GUICtrlCreateButton("454454", 5, 5, 100, 50)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit ;全部退出,能力有限,暂时没什么高招解决.当然,如果你能解决的话,希望你可以发上来分享
Case $jjjj
MsgBox(64,"提示","当前按钮被点击!!",10)
EndSwitch
WEnd
EndIf
Case $Button_3
if WinExists("子窗口3") = 0 Then
GuiCreate("子窗口3", 140, 60,160,100,-1,-1,$main)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
EndIf
Case $Button_1
if WinExists("子窗口1") = 0 Then
GuiCreate("子窗口1", 140, 60,300,100,-1,-1,$main)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
EndIf
EndSwitch
EndFunc ;==>gui
呵呵,还是用LS的吧!
[ 本帖最后由 ceoguang 于 2008-5-14 13:49 编辑 ] 呵呵,二楼的占内存不爽~还是OnEvent 模式好! 哈哈,onEvent模式要好好学习一下。 哈哈,几年前的帖子了。 也学习了。。 过来看看,OnEvent的确有很多地方值得深入 OnEvent,我也想学!
页:
[1]