主窗口点击按钮后又创建了一个新的子窗口,在关闭子窗口时主窗口也关闭了
大侠们帮帮忙看看我这个问题:主窗口上点击按钮,然后调用另外的窗口脚本,创建了一个子窗口出来,但在关闭子窗口时会将程序一起退出去,大家有没有办法可以只关闭子窗口,而不影响到主窗口,下次再主窗口上点击按钮后,又可以拉起这个子窗口来。 #include <GUIConstantsEx.au3>
_Main()
Func _Main()
;Initialize variables
Local $GUIWidth = 250, $GUIHeight = 250
Local $ParentWin, $ParentWin_Pos, $ChildWin, $msg
;Create main/parent window
$ParentWin = GUICreate("父窗体", $GUIWidth, $GUIHeight)
;Save the position of the parent window
$ParentWin_Pos = WinGetPos($ParentWin, "")
;Show the parent window/Make the parent window visible
GUISetState(@SW_SHOW)
;Create child window and add the parameter to make it the child of the parent window
$ChildWin = GUICreate("子窗体", $GUIWidth, $GUIHeight, $ParentWin_Pos + 100, $ParentWin_Pos + 100, -1, -1, $ParentWin)
;Show the child window/Make the child window visible
GUISetState(@SW_SHOW)
;Switch to the parent window
GUISwitch($ParentWin)
;Loop until:
;- user presses Esc when focused to the parent window
;- user presses Alt+F4 when focused to the parent window
;- user clicks the close button of the parent window
While 1
;After every loop check if the user clicked something in the GUI windows
$msg = GUIGetMsg(1)
Select
;Check if user clicked on a close button of any of the 2 windows
Case $msg = $GUI_EVENT_CLOSE
;Check if user clicked on the close button of the child window
If $msg = $ChildWin Then
MsgBox(64, "测试", "您关闭了子窗体.")
;Switch to the child window
GUISwitch($ChildWin)
;Destroy the child GUI including the controls
GUIDelete()
;Check if user clicked on the close button of the parent window
ElseIf $msg = $ParentWin Then
MsgBox(64, "测试", "您关闭了父窗体.")
;Switch to the parent window
GUISwitch($ParentWin)
;Destroy the parent GUI including the controls
GUIDelete()
;Exit the script
Exit
EndIf
EndSelect
WEnd
EndFunc ;==>_Main
D:\autoit3\Examples\GUI\Simple\child.au3 给的例子固然可以只是关闭子窗口,但是再用父窗口开创建子窗体依然创建不起来。 本帖最后由 xiehuahere 于 2012-7-31 19:38 编辑
回复 3# andyloving
在 2# 的基础上改了下:#include <GUIConstantsEx.au3>
Local $ParentWin, $ChildWin, $msg
$ParentWin = GUICreate("父窗体", 250, 250)
$Button = GUICtrlCreateButton("Popup", 75, 150, 100, 35)
GUISetState()
While 1
;After every loop check if the user clicked something in the GUI windows
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
GUISetState(@SW_DISABLE)
$ChildWin = GUICreate("子窗体", 200, 200, -1, -1, -1, -1, $ParentWin)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete($ChildWin)
GUISetState(@SW_ENABLE)
GUISetState(@SW_RESTORE)
EndSwitch
WEnd 找到方法了,谢谢两位。我的方法如下:#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form = GUICreate("Form1", 429, 155, 192, 124)
$Button = GUICtrlCreateButton("Button1", 216, 48, 137, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
XIXI()
EndSwitch
WEnd
;子窗口
Func XIXI()
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 460, 155, 400, 124)
$Button1 = GUICtrlCreateButton("Button1", 216, 48, 137, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$show= True
While $show
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
$show=False
Case $Button1
MsgBox(0,0,0)
EndSwitch
WEnd
EndFunc 不知这个适合你胃口不?
#include <GUIConstantsEx.au3>
$mainwindow = GUICreate("Hello World", 300, 200)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("opened the subform", 20, 30, 150)
$dummywindow = GUICreate("Dummy window for testing ", 200, 100)
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg(1)
Select
Case $msg = $okbutton
GUISetState(@SW_SHOW,$dummywindow)
Case $msg = $GUI_EVENT_CLOSE And $msg = $mainwindow
Exit
Case $msg = $GUI_EVENT_CLOSE And $msg = $dummywindow
GUISetState(@SW_HIDE,$dummywindow)
EndSelect
WEnd
回复 6# 鸟人
这个也是个不错的方法,非常感谢你! 好技术强帖
页:
[1]