找回密码
 加入
搜索
查看: 4169|回复: 12

[AU3基础] 主界面CASE 中如何在嵌套一个子界面CASE(已解决)

  [复制链接]
发表于 2012-5-3 11:24:47 | 显示全部楼层 |阅读模式
本帖最后由 iori2882 于 2012-5-4 08:38 编辑

我创建了一个界面,点击$Button2的时候再创建一个子窗口 在子窗口中建立个$Button1,点击$Button1 让他输出数据,但是我嵌套的时候,点$Button2的时候直接就输出数据了,没给我点$Button1的机会 为什么呢?
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 255, 132, 459, 264)
GUISetBkColor(0xA6CAF0)
$Button0 = GUICtrlCreateButton("Button0", 0, 0, 50, 25)
$Button2 = GUICtrlCreateButton("Button2", 88, 0, 50, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button0
                        MsgBox(0,0,2)
                Case $Button2
                        $Form2 = GUICreate("Form2", 225, 97, 16, 25, $WS_POPUP, $WS_EX_MDICHILD, $Form1)
                        $Combo1 = GUICtrlCreateCombo("1", 48, 40, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
                        GUICtrlSetData(-1, "2|3|4|5", "1")
                        $Button1 = GUICtrlCreateButton("Button1", 80, 80, 75, 25)
                        GUISetState(@SW_SHOW)
                        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;嵌套
                        Select
                        Case $Button1
                        MsgBox(0,0,1)
                        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;不起作用啊
                        EndSelect                
        EndSwitch
WEnd


方法在4楼
发表于 2012-5-3 12:26:02 | 显示全部楼层
本帖最后由 邪恶海盗 于 2012-5-3 12:27 编辑
#include <GUIConstants.au3>
#NoTrayIcon
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




#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
忘记在哪找到的多窗口实例了...


另外问一下,代码颜色是咋整的???
发表于 2012-5-3 12:50:05 | 显示全部楼层
发表于 2012-5-3 12:59:36 | 显示全部楼层
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Button1
Opt("GUIOnEventMode", 1)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 255, 132, 459, 264)
GUISetBkColor(0xA6CAF0)
$Button0 = GUICtrlCreateButton("Button0", 0, 0, 50, 25)
$Button2 = GUICtrlCreateButton("Button2", 88, 0, 50, 25)
GUISetState(@SW_SHOW)
_RegMsg($Form1, "Button_ClicK", "Button", 0, 2)

While 1
        Sleep(100)
WEnd

Func Button_ClicK()
        Switch @GUI_CtrlId
                Case $Button0
                        MsgBox(0, 0, 2)
                Case $Button1
                        MsgBox(0,0,1)
                Case $Button2
                        _Child()
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
EndFunc   ;==>Button_ClicK

Func _Child()
        $Form2 = GUICreate("Form2", 225, 97, 16, 25, $WS_POPUP, $WS_EX_MDICHILD, $Form1)
        $Combo1 = GUICtrlCreateCombo("1", 48, 40, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
        GUICtrlSetData(-1, "2|3|4|5", "1")
        $Button1 = GUICtrlCreateButton("Button1", 80, 80, 75, 25)
        GUICtrlSetOnEvent(-1,"Button_ClicK")
        GUISetState(@SW_SHOW)
;~         _RegMsg($Form2, "Button_ClicK", "Button", 1, 1)
        
EndFunc   ;==>_Child


;RegMsg(窗口句柄,函数名[,控件名,控件最小序号,控件最大序号])
Func _RegMsg($rHwnd, $rFunc, $rCtrl = Default, $rMin = Default, $rMax = Default)
        GUISwitch($rHwnd)
        If Opt("GUIEventOptions") Then
                For $i = -13 To -4
                        GUISetOnEvent($i, $rFunc)
                Next
        EndIf
        
        GUISetOnEvent(-3, $rFunc)
        
        If Not IsKeyword($rCtrl) Then
                If $rMin >= $rMax Then Return SetError(1, 0, 0)
                For $i = $rMin To $rMax
                        GUICtrlSetOnEvent(Eval($rCtrl & $i), $rFunc)
                Next
        EndIf
        Return SetError(0, 0, 1)
EndFunc   ;==>_RegMsg

评分

参与人数 1金钱 +30 贡献 +3 收起 理由
iori2882 + 30 + 3 谢谢

查看全部评分

 楼主| 发表于 2012-5-3 14:01:28 | 显示全部楼层
忘记在哪找到的多窗口实例了...


另外问一下,代码颜色是咋整的???
邪恶海盗 发表于 2012-5-3 12:26

你说的代码颜色是 我那界面上的蓝颜色么?

那个的话 只要在你的创建的窗体下 加上GUISetBkColor(0xA6CAF0)
就行了,,你给我的这个例子 我看了 就是绕不过去那个弯 怎么也实验不出来
发表于 2012-5-3 14:17:21 | 显示全部楼层
直接循环里调用FUNC不就行了。

评分

参与人数 1金钱 +10 收起 理由
iori2882 + 10

查看全部评分

 楼主| 发表于 2012-5-3 14:18:40 | 显示全部楼层
本帖最后由 iori2882 于 2012-5-3 14:33 编辑
风行者 发表于 2012-5-3 12:59

   谢谢风行了,,,_RegMsg这个函数是什么作用啊?从学习AU3的第一天起 用的都是消息循环模式,因为

帮助里给的例子都是这个模式,要实现我的那个需求 用消息循环模式也应该能做到吧?
发表于 2012-5-3 14:23:02 | 显示全部楼层
回复 7# iori2882


    下面Func EndFunc没看到???
发表于 2012-5-3 14:23:29 | 显示全部楼层
回复 5# iori2882


    我说的是论坛代码颜色...
 楼主| 发表于 2012-5-3 14:27:26 | 显示全部楼层
本帖最后由 iori2882 于 2012-5-3 14:29 编辑
回复  iori2882


    我说的是论坛代码颜色...
邪恶海盗 发表于 2012-5-3 14:23


[code][/code]
你把代码的 code 改成AU3的就行了
发表于 2012-5-3 14:31:25 | 显示全部楼层
回复 4# 风行者
谢谢,来学习的。
发表于 2012-5-3 14:38:49 | 显示全部楼层
回复 10# iori2882


   
ShellExecute("http://q.115.com/386")



这样???
发表于 2012-5-3 15:48:25 | 显示全部楼层
学习了……
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 13:33 , Processed in 0.095540 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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