找回密码
 加入
搜索
查看: 7905|回复: 9

[GUI管理] GUIGetMsg()重复怎么破?

  [复制链接]
发表于 2014-6-23 04:58:39 | 显示全部楼层 |阅读模式
本帖最后由 l4ever 于 2014-6-23 05:02 编辑

下面是官方的例子
运行之后鼠标狂点  Button1
等下弹出一大堆的msgbox
这是BUG么?
即便是弹出了msgbox,你不管他,接着点 Button1 ,然后你得关闭一大堆msgbox

后来试了试换个思路,用 GUICtrlSetOnEvent
还是官方的例子,居然还是酱紫.
autoit 版本:3.3.9.21

大家麻烦试试是不是这样的?
#include <GUIConstantsEx.au3>

Example()

;-------------------------------------------------------------------------------------
; Example - Press the button to see the value of the radio boxes
; The script also detects state changes (closed/minimized/timeouts, etc).
Func Example()
        Local $button_1, $radio_1, $radio_3
        Local $radioval1, $msg

        Opt("GUICoordMode", 1)
        GUICreate("Radio Box Demo", 400, 280)

        ; Create the controls
        $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
        GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
        GUIStartGroup()
        $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
        GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
        $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)

        ; Init our vars that we will use to keep track of GUI events
        $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button

        ; Show the GUI
        GUISetState()

        ; In this message loop we use variables to keep track of changes to the radios, another
        ; way would be to use GUICtrlRead() at the end to read in the state of each control
        While 1
                $msg = GUIGetMsg()
                Select
                        Case $msg = $GUI_EVENT_CLOSE
                                MsgBox(4096, "", "Dialog was closed")
                                Exit
                        Case $msg = $GUI_EVENT_MINIMIZE
                                MsgBox(4096, "", "Dialog minimized", 2)
                        Case $msg = $GUI_EVENT_MAXIMIZE
                                MsgBox(4096, "", "Dialog restored", 2)

                        Case $msg = $button_1 and $msg <> ""
                                $msg = ""
                                MsgBox(4096, "Default button clicked", "Radio " & $radioval1)

                        Case $msg >= $radio_1 And $msg <= $radio_3
                                $radioval1 = $msg - $radio_1

                EndSelect
                sleep(100)
        WEnd
EndFunc   ;==>Example
发表于 2014-6-23 15:35:16 | 显示全部楼层
本帖最后由 shqf 于 2014-6-23 15:36 编辑

程序设计的就是点Button1,就会运行msgbox,弹出一个对话框。
你点Button1 N下,就会弹出N个窗口,只是窗口会一个一个显示出来而已。即关闭前一个后才显示下一个,总之点击事件程序是已经接收到了。
你狂点Button1,还想让程序做什么反应呢?
发表于 2014-6-23 16:44:54 | 显示全部楼层
回复 1# l4ever

彈出前 要先把 GUI 凍結  那就不會造成 一跳出問題
发表于 2014-6-23 17:23:48 | 显示全部楼层
帮顶
发表于 2014-6-23 18:34:27 | 显示全部楼层
你弄过GUI替代 maXBOX不就完事了,msgbox会中断程序,尽量少使用把。
发表于 2014-6-24 14:22:46 | 显示全部楼层
本帖最后由 pcbar 于 2014-6-24 14:41 编辑

#include <GUIConstantsEx.au3>

Example()

;-------------------------------------------------------------------------------------
; Example - Press the button to see the value of the radio boxes
; The script also detects state changes (closed/minimized/timeouts, etc).
Func Example()
        Local $button_1, $radio_1, $radio_3
        Local $radioval1, $msg

        Opt("GUICoordMode", 1)
        GUICreate("Radio Box Demo", 400, 280)

        ; Create the controls
        $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
        GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
        GUIStartGroup()
        $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
        GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
        $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)

        ; Init our vars that we will use to keep track of GUI events
        $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button

        ; Show the GUI
        GUISetState()

        ; In this message loop we use variables to keep track of changes to the radios, another
        ; way would be to use GUICtrlRead() at the end to read in the state of each control
        While 1
                $msg = GUIGetMsg()
                Select
                        Case $msg = $GUI_EVENT_CLOSE
                                MsgBox(4096, "", "Dialog was closed")
                                Exit
                        Case $msg = $GUI_EVENT_MINIMIZE
                                MsgBox(4096, "", "Dialog minimized", 2)
                        Case $msg = $GUI_EVENT_MAXIMIZE
                                MsgBox(4096, "", "Dialog restored", 2)

                        Case $msg = $button_1
                                GUICtrlSetState($button_1, $gui_disable)
                                MsgBox(4096, "Default button clicked", "Radio " & $radioval1)
                                GUICtrlSetState($button_1, $gui_enable)
                        Case $msg >= $radio_1 And $msg <= $radio_3
                                $radioval1 = $msg - $radio_1

                EndSelect
               
        WEnd
EndFunc   ;==>Example
发表于 2014-6-25 19:30:02 | 显示全部楼层
这是官方的例子吗?不象啊,
官方例子不会出现sleep(100)
和Case $msg = $button_1 and $msg <> ""
                                $msg = ""
的低级问题的
发表于 2014-6-25 20:13:47 | 显示全部楼层
这是官方的例子吗?不象啊,
官方例子不会出现sleep(100)
和Case $msg = $button_1 and $msg  ""
       ...
seniors 发表于 2014-6-25 19:30



    确实…
发表于 2014-6-25 21:01:32 | 显示全部楼层
这段代码蛋疼得很~
发表于 2014-6-25 21:08:26 | 显示全部楼层
像我这种菜中菜只有看到的份
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-5 01:12 , Processed in 0.076883 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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