au3多窗口 实例
- #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
复制代码 |