[已解决]为什么这个子窗口只能运行一次
本帖最后由 laomao127 于 2010-12-13 13:33 编辑#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\1.kxf
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Label1 = GUICtrlCreateLabel("Label1", 112, 128, 60, 25)
$Button1 = GUICtrlCreateButton("Button1", 192, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
fu()
EndSwitch
WEnd
Func fu()
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 192, 144, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 192, 192, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete() ; 销毁前面的窗口
EndSwitch
WEnd
EndFunc这个代码是运行子窗口,为什么这个子窗口只能运行一次,关闭子窗口后在点 提交按钮就不能运行了,这是怎么回事呢? 请高手帮忙 请高手帮忙 本帖最后由 yhxhappy 于 2010-12-13 11:49 编辑
下面已经改好,具体原因我也说不清楚,但是做子窗口不建议楼主这样的写法,可以选创建两个窗口,再根据按钮来显示或隐藏子窗口#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Label1 = GUICtrlCreateLabel("Label1", 112, 128, 60, 25)
$Button = GUICtrlCreateButton("Button1", 192, 128, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button
fu()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func fu()
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 192, 144, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 192, 192, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete() ; 销毁前面的窗口
ExitLoop
EndSwitch
WEnd
EndFunc 回复 3# yhxhappy
这个也是只能运行一次,
运行程序后,第一次点 按钮可以打开,关闭子窗口后,在运行按钮就不能打开了,您说不建议我这样写 麻烦您把您的方法给写一下可以吗?谢谢 本帖最后由 lxz 于 2010-12-13 11:56 编辑
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Label1 = GUICtrlCreateLabel("Label1", 112, 128, 60, 25)
$Button1 = GUICtrlCreateButton("Button1", 192, 128, 75, 25)
$Form2 = GUICreate("Form2", 633, 447, 192, 124)
$Button2 = GUICtrlCreateButton("退出", 192, 144, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 192, 192, 75, 25)
GUISwitch($Form1)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Switch $nMsg
Case $Form1
Exit
Case $WinSub
GUISwitch($Form2)
GUISetState(@SW_HIDE)
EndSwitch
Case $Button1
GUISwitch($Form2)
GUISetState(@SW_SHOW)
Case $Button2
Exit
Case $Button3
GUISwitch($Form2)
GUISetState(@SW_HIDE)
EndSwitch
WEnd $Fgui = GUICreate('父窗口', 250, 250)
$But1 = GUICtrlCreateButton('创建“子窗体”', 75, 100, 100, 30, 0)
GUISetState() ;调整窗口的状态.
While 1
Switch GUIGetMsg()
Case - 3
Exit
Case $But1
GUISetState(@SW_DISABLE, $Fgui) ;禁用父窗口
$Sgui = GUICreate('子窗口', 200, 200) ;创建子窗口
$But2 = GUICtrlCreateButton("关闭\退出", 50, 80, 100, 30, 0) ;创建“退出”按钮
GUISetState() ;调整窗口的状态.
While 1
Switch GUIGetMsg()
Case - 3
GUISetState(@SW_ENABLE, $Fgui) ;启用父窗口
GUIDelete($Sgui) ;删除指定窗口和它包含的所有控件.
ExitLoop ;终止一个 While/Do/For 循环.
Case $But2
GUISetState(@SW_ENABLE, $Fgui) ;启用父窗口
GUIDelete($Sgui) ;;删除指定窗口和它包含的所有控件.
ExitLoop ;终止一个 While/Do/For 循环.
EndSwitch
WEnd
EndSwitch
WEnd Opt("GUIOnEventMode", 1)
$Main_GUI = GUICreate("父窗口", 280, 280)
GUISetOnEvent(-3, "_GuiMsg")
$Btn_Show = GUICtrlCreateButton("子窗口", 92, 110, 100, 30)
GUISetState(@SW_SHOW, $Main_GUI)
$Child1_GUI = GUICreate("子窗口", 200, 100)
GUISetOnEvent(-3, "_GuiMsg")
$Btn_Test1 = GUICtrlCreateButton("显示", 50, 20, 100, 30)
GUICtrlSetOnEvent($Btn_Show, "_GuiMsg")
GUICtrlSetOnEvent($Btn_Test1, "_GuiMsg")
While 1
Sleep(250)
WEnd
Func _GuiMsg()
Switch @GUI_CtrlId
Case - 3
Switch @GUI_WinHandle
Case $Main_GUI
Exit
Case $Child1_GUI
GUISetState(@SW_ENABLE, $Main_GUI)
GUISetState(@SW_HIDE, $Child1_GUI)
EndSwitch
Case $Btn_Show
GUISetState(@SW_SHOW, $Child1_GUI)
GUISetState(@SW_DISABLE, $Main_GUI)
Case $Btn_Test1
MsgBox(64, "测试", "我是子窗口")
EndSwitch
EndFunc ;==>_GuiMsg 楼上正解。 路过,积分中。。。。。
页:
[1]