找回密码
 加入
搜索
查看: 3121|回复: 8

郁闷,关于OnEvent 模式的问题

  [复制链接]
发表于 2008-5-14 11:17:30 | 显示全部楼层 |阅读模式
在下面这个例子中,我要怎么实现对子窗口按钮的响应呢?
帮我瞧瞧!


#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 编辑 ]
发表于 2008-5-14 13:00:18 | 显示全部楼层
...............子窗口没这么麻烦吧?看这个例子

#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[0]
                Case $GUI_EVENT_CLOSE
                        Switch $nMsg[1]
                                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
发表于 2008-5-14 13:46:39 | 显示全部楼层
#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 编辑 ]
 楼主| 发表于 2008-5-14 20:53:03 | 显示全部楼层
呵呵,二楼的占内存不爽~还是OnEvent 模式好!
发表于 2011-2-8 17:45:44 | 显示全部楼层
哈哈,onEvent模式要好好学习一下。
发表于 2011-2-10 21:40:57 | 显示全部楼层
哈哈,几年前的帖子了。
发表于 2011-5-24 21:39:31 | 显示全部楼层
也学习了。。
发表于 2013-4-11 08:25:30 | 显示全部楼层
过来看看,OnEvent的确有很多地方值得深入
发表于 2013-4-16 07:11:49 | 显示全部楼层
OnEvent,我也想学!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-29 07:20 , Processed in 0.077303 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表