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

[图形处理] [已解决]为什么这个子窗口只能运行一次

  [复制链接]
发表于 2010-12-13 10:56:04 | 显示全部楼层 |阅读模式
本帖最后由 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
这个代码是运行子窗口,为什么这个子窗口只能运行一次,关闭子窗口后在点 提交按钮就不能运行了,这是怎么回事呢? 请高手帮忙

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2010-12-13 11:02:01 | 显示全部楼层
请高手帮忙
发表于 2010-12-13 11:16:59 | 显示全部楼层
本帖最后由 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

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-12-13 11:39:06 | 显示全部楼层
回复 3# yhxhappy


    这个也是只能运行一次,
运行程序后,第一次点 按钮可以打开,关闭子窗口后,在运行按钮就不能打开了,您说不建议我这样写 麻烦您把您的方法给写一下可以吗?谢谢
发表于 2010-12-13 11:46:19 | 显示全部楼层
本帖最后由 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[0]                      
    Case $GUI_EVENT_CLOSE               
        Switch $nMsg[1]                
           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

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-12-13 11:53:46 | 显示全部楼层
$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
发表于 2010-12-13 11:58:02 | 显示全部楼层
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金钱 +30 收起 理由
afan + 30

查看全部评分

发表于 2010-12-13 13:18:16 | 显示全部楼层
楼上正解。
发表于 2011-7-15 13:31:11 | 显示全部楼层
路过,积分中。。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 17:00 , Processed in 0.074050 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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