找回密码
 加入
搜索
查看: 10219|回复: 19

怎么使子窗口出现在最前面 无法操作父窗口

 火.. [复制链接]
发表于 2008-8-14 10:39:07 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 269, 141, 372, 253)
$Button1 = GUICtrlCreateButton("Button1", 40, 56, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 136, 56, 75, 25, 0)
GUISetState(@SW_SHOW)


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        manager()
        EndSwitch
WEnd

Func manager()
$Form2 = GUICreate("Form2", 239, 100, 372, 253)
$Button1 = GUICtrlCreateButton("Button1", 40, 56, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 136, 56, 75, 25, 0)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                                GUIDelete($Form2)
                                WinActivate("Form2")
                                GUISetState(@SW_ENABLE, $Form1)
                                ExitLoop
        EndSwitch
WEnd
EndFunc



简单点说就是在父窗口上点出子窗口来
然后子窗口在最顶层   而且不能操作父窗口 必须把子窗口关掉才能操作父窗口
怎么实现?  因为做的软件需要这个功能  请大家帮忙

[ 本帖最后由 kryiran 于 2008-8-21 21:31 编辑 ]
发表于 2008-8-14 20:13:15 | 显示全部楼层
试试
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 269, 141, 372, 253)
$Button1 = GUICtrlCreateButton("Button1", 40, 56, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 136, 56, 75, 25, 0)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUISetState(@SW_DISABLE,$Form1)
                        manager()
                        GUISetState(@SW_ENABLE,$Form1)
        EndSwitch
WEnd

Func manager()
$Form2 = GUICreate("Form2", 239, 100, -1,-1)
$Button1 = GUICtrlCreateButton("Button1", 40, 56, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 136, 56, 75, 25, 0)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                                GUIDelete($Form2)
                                WinActivate("Form2")
                                GUISetState(@SW_ENABLE, $Form1)
                                ExitLoop
        EndSwitch
WEnd
EndFunc
 楼主| 发表于 2008-8-15 00:46:35 | 显示全部楼层

成功到是成功了

但是子窗口退出后 父窗口为什么会最小化呢?  很郁闷
发表于 2008-8-15 07:38:28 | 显示全部楼层
不建议使用多重循环嵌套.
先写出gui,在需要的时候GUISetState(@SW_SHOW,hwnd),用完了再关闭.
发表于 2008-8-15 07:40:26 | 显示全部楼层
父子窗口建议用GUIOnEventMode模式。
发表于 2008-8-15 13:26:41 | 显示全部楼层

为什么不建议使用多重循环嵌套?

#include <GUIConstantsex.au3>
$mainwindow = GUICreate('$strmaintitle', 371, 354)
$Button3 = GUICtrlCreateButton("新建...", 101, 272, 75, 25, 0)
 
GUISetState()
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button3
            GUISetState(@SW_DISABLE,$mainwindow)
            $newindow = GUICreate('$strnewtitle', 300, 200)
            $newindowCancel = GUICtrlCreateButton("cancel", 156, 112, 75, 25, 0)
            GUISetState()
            While 1
                Switch guigetmsg()
                    Case $GUI_EVENT_CLOSE
                            GUISetState(@SW_ENABLE,$mainwindow)
                            GUIDelete($newindow)
                            ExitLoop
                    Case $newindowCancel
                            GUISetState(@SW_ENABLE,$mainwindow)
                            GUIDelete($newindow)
                            ExitLoop
                EndSwitch
            WEnd
    EndSwitch
WEnd

这样应该是多重循环嵌套吧?我经常这样用
发表于 2008-8-15 13:28:26 | 显示全部楼层
在多窗口的时候GUIOnEventMode模式比多重循环要好。
建议阅读一下zcbenz的大作。并自己实际测试一下,就会知道了。
发表于 2008-8-15 21:40:49 | 显示全部楼层
原帖由 kakinkgb 于 2008-8-15 13:26 发表
[au3]#include
$mainwindow = GUICreate('$strmaintitle', 371, 354)
$Button3 = GUICtrlCreateButton("新建...", 101, 272, 75, 25, 0)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $ ...

占用cpu/容易出错/不便于阅读/不便于修改......
发表于 2010-6-27 00:51:57 | 显示全部楼层
学习了,谢谢
发表于 2010-12-2 01:34:01 | 显示全部楼层
认真学习 顶
发表于 2011-5-4 17:10:03 | 显示全部楼层
正在研究父子窗口问题`~搜索下就找到了这个帖子,谢谢各位高手指教`~
发表于 2011-6-11 23:36:08 | 显示全部楼层
受教呀,非常感谢
发表于 2011-6-12 00:10:06 | 显示全部楼层
以前的例子

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $B1, $F1, $F2
Opt("GUIOnEventMode", 1)
father()
Func father()
        $F1 = GUICreate("father", 608, 456, 192, 124)
        GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
        GUISetBkColor(0x335EA8)
        $B1 = GUICtrlCreateButton("son", 472, 384, 105, 41)
        GUICtrlSetOnEvent($B1, "gui")
        GUISetState(@SW_SHOW)
EndFunc   ;==>father

Func son()
        $F2 = GUICreate("son", 413, 298, 193, 123)
        GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
        GUISetBkColor(0x800080)
        GUISetState(@SW_SHOW)

EndFunc   ;==>son
While 1
        ;
WEnd
Func gui()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Switch @GUI_WinHandle
                                Case $F1
                                        Exit
                                Case $F2
                                        GUISetState(@SW_HIDE, $F2)
                                        GUISetState(@SW_ENABLE, $F1)
                                        WinActivate("father")
                        EndSwitch
                Case $B1
                        GUISetState(@SW_DISABLE, $F1)
                        son()
        EndSwitch
EndFunc   ;==>gui

发表于 2012-1-9 09:42:16 | 显示全部楼层
研究下,子窗口
发表于 2012-1-12 20:18:55 | 显示全部楼层
剛剛才玩父、子窗口,有源碼參考,做出了自己想要的窗口...
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 16:20 , Processed in 0.150846 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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