找回密码
 加入
搜索
查看: 2691|回复: 4

[GUI管理] GUI事件之父窗口-生动的例子[已解决]

[复制链接]
发表于 2015-9-14 20:13:58 | 显示全部楼层 |阅读模式
本帖最后由 Huiseyu 于 2015-9-15 18:53 编辑

有三个窗口,不知道怎么关掉其中一个。GUI还是没搞懂。
$hGUI = GUICreate('GUI-MAIN' ,250,300 ,Default ,Default ,0x10070000)
$oGUI = GUICreate('windows1' ,200,150 ,-250 ,Default ,0x10070000 ,0x0000040 ,$hGUI)
$iGUI = GUICreate('windows2' ,200,150 ,250 ,Default ,0x10070000 ,0x0000040 ,$oGUI)

While 1

        If GUIGetMsg($hGUI) = -3 then Exit             ;退出
        If GUIGetMsg($oGUI) = -3 then GUIDelete($oGUI) ;关掉 $oGUI ,这个不会
        If GUIGetMsg($iGUI) = -3 then GUIDelete($iGUI) ;关掉 $iGUI ,......

WEnd
发表于 2015-9-14 21:32:53 | 显示全部楼层
Local $hGUI1 = -1, $hGUI2 = -1
$hGUI = GUICreate('GUI-MAIN', 250, 300, Default, Default, 0x10070000)
$b1 = GUICtrlCreateButton('window1', 20, 50)
$b2 = GUICtrlCreateButton('window2', 150, 50)
GUISetState()
While 1
        $msg = GUIGetMsg(1)
        If Not IsArray($msg) Then ContinueLoop
        Switch $msg[0]
                Case -3
                        If $msg[1] = $hGUI Then
                                Exit
                        ElseIf $msg[1] = $hGUI1 Then
                                GUIDelete($hGUI1)
                                $hGUI1 = -1
                        ElseIf $msg[1] = $hGUI2 Then
                                GUIDelete($hGUI2)
                                $hGUI2 = -1
                        EndIf
                Case $b1
                        If $hGUI1 = -1 Then
                                $hGUI1 = GUICreate('windows1', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
                        Else
                                WinActivate($hGUI1)
                        EndIf
                Case $b2
                        If $hGUI2 = -1 Then
                                $hGUI2 = GUICreate('windows2', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
                        Else
                                WinActivate($hGUI2)
                        EndIf
        EndSwitch
WEnd

评分

参与人数 1金钱 +10 收起 理由
Huiseyu + 10 sky

查看全部评分

发表于 2015-9-14 21:46:38 | 显示全部楼层
用事件模式,更一目了然
Opt('guioneventmode', 1)
Local $hGUI1 = -1, $hGUI2 = -1
$hGUI = GUICreate('GUI-MAIN', 250, 300, Default, Default, 0x10070000)
GUISetOnEvent(-3, '_exit')
$b1 = GUICtrlCreateButton('window1', 20, 50)
GUICtrlSetOnEvent(-1, '_hGui1')
$b2 = GUICtrlCreateButton('window2', 150, 50)
GUICtrlSetOnEvent(-1, '_hGui2')
GUISetState()
While 1
        Sleep(100)
WEnd

Func _exit()
                 Exit
EndFunc

Func _hGui1()
        If $hGUI1 = -1 Then
                $hGUI1 = GUICreate('windows1', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
                GUISetOnEvent(-3, '_del_gui1')
        Else
                WinActivate($hGUI1)
        EndIf
EndFunc   ;==>_hGui1

Func _hGui2()
        If $hGUI2 = -1 Then
                $hGUI2 = GUICreate('windows2', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
                GUISetOnEvent(-3, '_del_gui2')
        Else
                WinActivate($hGUI2)
        EndIf
EndFunc   ;==>_hGui2

Func _del_gui1()
        GUIDelete($hGUI1)
        $hGUI1 = -1
EndFunc   ;==>_del_gui1

Func _del_gui2()
        GUIDelete($hGUI2)
        $hGUI2 = -1
EndFunc   ;==>_del_gui2
发表于 2015-9-14 21:56:06 | 显示全部楼层
嫌3楼函数过多太散乱,可以整合一下。
Opt('guioneventmode', 1)
Local $hGUI1 = -1, $hGUI2 = -1
$hGUI = GUICreate('主窗口', 250, 300, Default, Default, 0x10070000)
GUISetOnEvent(-3, '_exit')
$b1 = GUICtrlCreateButton('子窗口1', 20, 50)
GUICtrlSetOnEvent(-1, '_c_c_windows')
$b2 = GUICtrlCreateButton('子窗口2', 150, 50)
GUICtrlSetOnEvent(-1, '_c_c_windows')
GUISetState()
While 1
        Sleep(100)
WEnd

Func _exit()
        Switch @GUI_WinHandle
                Case $hGUI
                        Exit
                Case $hGUI1
                        GUIDelete($hGUI1)
                        $hGUI1 = -1
                Case $hGUI2
                        GUIDelete($hGUI2)
                        $hGUI2 = -1
        EndSwitch
EndFunc

Func _c_c_windows()
        Local $i = @GUI_CtrlId - 2
        If Eval('hGUI' & $i) = -1 Then
                Assign('hGUI' & $i, GUICreate('子窗口' & $i, 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI))
                GUISetOnEvent(-3, '_exit')
        Else
                WinActivate(Eval('hGUI' & $i))
        EndIf
EndFunc
 楼主| 发表于 2015-9-15 18:46:00 | 显示全部楼层
嫌3楼函数过多太散乱,可以整合一下。
Alam 发表于 2015-9-14 21:56



    完爆解决+收藏。。。,谢谢这么多生动的例子,非常感谢。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 15:52 , Processed in 0.078785 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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