找回密码
 加入
搜索
查看: 535|回复: 5

[网络通信] 如何通过代码非手动关闭独立GUI窗口?[已解决]

[复制链接]
发表于 2022-7-24 10:05:25 | 显示全部楼层 |阅读模式
本帖最后由 cashiba 于 2022-7-24 16:04 编辑
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
        Opt("GUICoordMode", 1)
        GUICreate("", 400, 280)
        Local $idButton_1 = GUICtrlCreateButton("按钮 1 &u", 30, 20, 120, 40)
        GUICtrlCreateGroup("组框 1", 30, 90, 165, 160)
        GUIStartGroup()
        Local $idRadio_1 = GUICtrlCreateRadio("单选框 &0", 50, 120, 90, 20)
        Local $idRadio_2 = GUICtrlCreateRadio("单选框 &1", 50, 150, 90, 20)
        Local $idRadio_3 = GUICtrlCreateRadio("单选框 &2", 50, 180, 90, 20)
        GUISetState(@SW_SHOW)
        
        Local $idMsg = 0
        While 1
                $idMsg = GUIGetMsg()
                Switch $idMsg
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $idButton_1
                        Case $idRadio_1, $idRadio_2, $idRadio_3
                                Local $aList = WinList()
                                For $i = 1 To $aList[0][0]
                                        If $aList[$i][0] And StringInStr($aList[$i][0], "单选框 ") Then
                                                WinClose($aList[$i][1])
                                                ;WinKill($aList[$i][1])
                                        EndIf
                                Next

                                GuiNew("单选框 " & String($idMsg - $idRadio_1))
                EndSwitch
        WEnd
        GUIDelete()
EndFunc   ;==>Example
Func GuiNew($GTitle)
        Local $hGUI = GUICreate($GTitle, -1, 216, -1, 5)
        GUISetState(@SW_SHOW, $hGUI)

        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd
        GUIDelete($hGUI)
EndFunc   ;==>GuiNew

如上,希望在点击单选框时自动弹出以单选框文本为标题的辅助新窗口,
并且点击切换单选框弹出新窗口之前会自动关闭旧窗口,减少手动关闭这一步骤。

如果把辅助新窗口的控件和事件ID都集中写在主窗口里,通过GUIGetMsg(1)来管理问题不大。
但如果把辅助新窗口做为独立窗口来对待,好像无法通过代码自动关闭。
有谁知道的,请赐教...


发表于 2022-7-24 10:31:51 | 显示全部楼层
主循环只用一个就行的了。使用事件模式会让你更好设计。创建窗口与关闭(或销毁),分开写。

评分

参与人数 1金钱 +30 收起 理由
cashiba + 30 谢谢!

查看全部评分

 楼主| 发表于 2022-7-24 10:41:20 | 显示全部楼层
绿色风 发表于 2022-7-24 10:31
主循环只用一个就行的了。使用事件模式会让你更好设计。创建窗口与关闭(或销毁),分开写。

谢谢风大侠!
改事件模式有不少地方要改,也有些麻烦。我是想尝试独立窗口独立操作,各个窗口的代码分开写在各自窗口里也有优点。
感觉这个像是用代码关闭_arraydisplay函数界面一样。貌似又涉及到了多线程?
发表于 2022-7-24 14:38:52 | 显示全部楼层
用事件模式会方便很多;另外子窗口可以采用先创建,之后都用显隐的方式切换更方便。
当然,你的想法也可以实现
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $idRadio_1, $idRadio_2, $idRadio_3, $iBfID
Example()

Func Example()
        Opt("GUICoordMode", 1)
        GUICreate("", 400, 280)
        Local $idButton_1 = GUICtrlCreateButton("按钮 1 &u", 30, 20, 120, 40)
        GUICtrlCreateGroup("组框 1", 30, 90, 165, 160)
        GUIStartGroup()
        $idRadio_1 = GUICtrlCreateRadio("单选框 &0", 50, 120, 90, 20)
        $idRadio_2 = GUICtrlCreateRadio("单选框 &1", 50, 150, 90, 20)
        $idRadio_3 = GUICtrlCreateRadio("单选框 &2", 50, 180, 90, 20)
        GUISetState(@SW_SHOW)

        Local $idMsg = 0
        While 1
                $idMsg = GUIGetMsg()
                Switch $idMsg
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $idButton_1
                        Case $idRadio_1, $idRadio_2, $idRadio_3
                                $iBfID = $idMsg
                                GuiNew("单选框 " & String($idMsg - $idRadio_1))
                EndSwitch
        WEnd
        GUIDelete()
EndFunc   ;==>Example
Func GuiNew($GTitle)
        Local $hGUI = GUICreate($GTitle, -1, 216, -1, 5)
        GUISetState(@SW_SHOW, $hGUI)
        Local $stt = ''
        While 1
                $idMsg = GUIGetMsg()
                Switch $idMsg
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $idRadio_1, $idRadio_2, $idRadio_3
                                If $idMsg = $iBfID Then ContinueCase
                                $iBfID = $idMsg
                                $stt = "单选框 " & ($idMsg - $idRadio_1)
                                ExitLoop
                EndSwitch
        WEnd
        GUIDelete($hGUI)
        If $stt <> '' Then GuiNew($stt)
EndFunc   ;==>GuiNew

评分

参与人数 1金钱 +30 收起 理由
cashiba + 30 谢谢!

查看全部评分

发表于 2022-7-24 15:10:35 | 显示全部楼层
GuiNew("单选框 " & String($idMsg - $idRadio_1))

可以这么写,直接读控件文本.
GuiNew(GUICtrlRead($idMsg, 1))

评分

参与人数 1金钱 +30 收起 理由
cashiba + 30 谢谢!

查看全部评分

 楼主| 发表于 2022-7-24 16:02:04 | 显示全部楼层
afan 发表于 2022-7-24 14:38
用事件模式会方便很多;另外子窗口可以采用先创建,之后都用显隐的方式切换更方便。
当然,你的想法也可以 ...

A大高手就是思路开阔,声明几个全局变量就解决了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-27 13:29 , Processed in 0.083387 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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