找回密码
 加入
搜索
查看: 78308|回复: 168

[原创] 新手必读之多窗口操作(隐藏/显示法)

 火... [复制链接]
发表于 2008-5-5 04:45:45 | 显示全部楼层 |阅读模式
Au3中多窗口操作(隐藏/显示法)实例:

一 GUIOnevent模式
#include <GUIConstants.au3>
Opt("GUIOneventMode",1)
Dim $Button[6]

$WinMain  = GUICreate("主窗口", 450, 300)            ;创建主窗口
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")             ;注册窗口关闭事件到函数_Exit
$Button[0]  = GUICtrlCreateButton("显示子窗口 1", 0, 0, 113, 49)
$Button[1]  = GUICtrlCreateButton("显示子窗口 2", 216, 0, 105, 49)

$WinSub1  = GUICreate("子窗口", 220, 60)                ;创建子窗口1
GUISetOnEvent($GUI_EVENT_CLOSE, "GUICtrlMsg")           ;注册窗口关闭事件到函数GUICtrlMsg
$Button[2] = GUICtrlCreateButton("确认", 0, 0, 100, 50)
$Button[3] = GUICtrlCreateButton("取消", 110, 0, 100, 50);创建子窗口中按钮二

$WinSub2  = GUICreate("子窗口", 220, 60)                ;创建子窗口2
GUISetOnEvent($GUI_EVENT_CLOSE, "GUICtrlMsg")           ;注册窗口关闭事件到函数GUICtrlMsg
$Button[4] = GUICtrlCreateButton("确认", 0, 0, 100, 50)
$Button[5] = GUICtrlCreateButton("取消", 110, 0, 100, 50);创建子窗口中按钮二

For $I = 5 To 0 Step -1
        GUICtrlSetOnEvent($Button[$I],"GUICtrlMsg") ;注册总共的六个按钮点击事件到函数 GUICtrlMsg
                                                    ;请区分 GUISetOnEvent 和 GUICtrlSetOnEvent的区别
Next

GUISwitch($WinMain)                            ;切换当前窗口到主窗口
GUISetState(@SW_SHOW)                          ;显示当前窗口

While 1
        Sleep(1000)
WEnd

Func GUICtrlMsg()
        Switch @GUI_CtrlId;选择事件 ID 或 控件 ID
                Case $GUI_EVENT_CLOSE;如果点下的是$GUI_EVENT_CLOSE(关闭)
                        GUISetState(@SW_HIDE,@GUI_WinHandle);  隐藏产生事件的窗口
                Case $Button[0]
                        GUISetState(@SW_SHOW,$WinSub1);  显示 子窗口 1
                Case $Button[1]
                        GUISetState(@SW_SHOW,$WinSub2);  显示 子窗口 2
                Case $Button[2]
                        MsgBox(48,0,"你点了子窗口 1 中的第一个按钮")
                Case $Button[3]
                        GUISetState(@SW_HIDE,$WinSub1);  隐藏 子窗口 1
                Case $Button[4]
                        MsgBox(48,0,"你点了主窗口 2 中的第一个按钮")
                Case $Button[5]
                        GUISetState(@SW_HIDE,$WinSub2);  隐藏 子窗口 2
        EndSwitch
EndFunc

Func _Exit()
        Exit
EndFunc




二 GUI消息循环模式
#include <GUIConstants.au3>

$WinMain  = GUICreate("主窗口", 450, 300)                ;创建主窗口
$Button1  = GUICtrlCreateButton("1", 0, 0, 113, 49, 0)
$Button2  = GUICtrlCreateButton("显示子窗口", 216, 0, 105, 49, 0);创建主窗口中按钮二

$WinSub   = GUICreate("子窗口", 220, 60)                ;创建子窗口
$Button21 = GUICtrlCreateButton("确认", 0, 0, 100, 50)
$Button22 = GUICtrlCreateButton("取消", 110, 0, 100, 50);创建子窗口中按钮二

GUISwitch($WinMain)                                     ;切换当前窗口到主窗口
GUISetState(@SW_SHOW)                                   ;显示当前窗口

While 1
        $nMsg = GUIGetMsg(1)  ;捕获窗口消息

;~ 在这里,$nMsg是一个数组,相关说明:
;~ $nMsg[0] = 0 或 事件 ID 或 控件 ID
;~ $nMsg[1] = 产生事件的窗口句柄
;~ $nMsg[2] = 产生事件的控件句柄(若适用)
;~ $nMsg[3] = 鼠标指针的当前 X 坐标(相对于 GUI 窗口)
;~ $nMsg[4] = 鼠标指针的当前 Y 坐标(相对于 GUI 窗口)

  Switch $nMsg[0]                       ;选择事件 ID 或 控件 ID
    Case $GUI_EVENT_CLOSE               ;如果点下的是$GUI_EVENT_CLOSE(关闭)
        Switch $nMsg[1]                ;  选择产生事件的窗口
           Case $WinMain               ;  如果是主窗口
               Exit                     ;  退出
           Case $WinSub                ;  如果是子窗口
               GUISwitch($WinSub)       ;  切换当前窗口到子窗口
               GUISetState(@SW_HIDE)    ;  隐藏当前窗口
         EndSwitch
    Case $Button1
       MsgBox(0, "你好", "你点了第一个按钮")
    Case $Button2                        ;如果点下的是主窗口中的按钮二
        GUISwitch($WinSub)                ;  切换当前窗口到子窗口
       GUISetState(@SW_SHOW)              ;  显示当前窗口
    Case $Button21
       MsgBox(0, "你好", "你点了子窗口第一个按钮")
    Case $Button22                       ;如果点下的是主窗口中的按钮二
       GUISwitch($WinSub)                 ;  切换当前窗口到子窗口
       GUISetState(@SW_HIDE)              ;  隐藏当前窗口
  EndSwitch
WEnd






[ 本帖最后由 漠北雪~狼 于 2008-5-12 23:53 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2008-5-5 12:29:20 | 显示全部楼层
又学习到新东西
发表于 2008-5-5 15:36:33 | 显示全部楼层
学习学习,呵
发表于 2008-5-5 20:27:09 | 显示全部楼层
学习到新的知识
发表于 2008-5-6 14:31:15 | 显示全部楼层
呵呵,仔细看了看,可惜还不能全明白。。。努力。。。
发表于 2008-5-6 15:41:43 | 显示全部楼层
学习新的知识。。
发表于 2008-5-7 18:33:53 | 显示全部楼层
不明白,学习ing
发表于 2008-5-7 18:56:00 | 显示全部楼层
呵呵
当老师还可以哦
发表于 2008-5-7 23:02:36 | 显示全部楼层
顶下..学习中
发表于 2008-5-11 14:37:54 | 显示全部楼层
主要是逻辑判断..考思想 .
发表于 2009-1-10 12:32:32 | 显示全部楼层
下来学习学习
发表于 2009-1-31 02:54:00 | 显示全部楼层
有猛...見識到了
发表于 2009-2-13 20:22:13 | 显示全部楼层
看了就顶 没什么要说的
发表于 2009-2-16 00:05:41 | 显示全部楼层
不错,谢谢大哥.
发表于 2009-2-17 14:18:33 | 显示全部楼层
支持下。。。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-24 11:57 , Processed in 0.081981 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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