找回密码
 加入
搜索
查看: 5875|回复: 5

[GUI管理] 事件模式—点击GUI按钮开始循环检测后,关闭和其他按钮就无反应了。

  [复制链接]
发表于 2012-11-12 15:11:59 | 显示全部楼层 |阅读模式
问个问题,GUI界面下2个按钮,一个按钮用于启动循环检测,另一按钮用于停止循环检测。
但是,在启动循环检测后,点其他的按钮就无效了,关闭窗口也无效,只能从托盘关闭。

请问,如何解决?
#include-once
#include <1.au3>   ;公共函数文档
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("仓位核查", 920, 345, 277, 113)
$list=GUICtrlCreateListView("品种|多单|空单|净头寸", 16, 72, 433, 257)
$Button1 = GUICtrlCreateButton("当前持仓", 96, 16, 89, 25)
GUISetState(@SW_SHOW)
;FindTheoryKeepFile()
$Button2 = GUICtrlCreateButton("Button1", 232, 16, 75, 25)
Do
        $msg = GUIGetMsg()

                While $msg=$Button1
                        GUICtrlCreateListViewItem ( "IF|10|-1|9" , $list)
                        Sleep(50)
                        If $msg<>$Button1 Then ExitLoop
                        WEnd
;        If $msg=$Button1 Then
;                GUICtrlCreateListViewItem ( "IF|10|-1|9" , $list)
                ;Beep ( 1500,100 ) 
                ;Beep ( 1500,100 ) 
                ;Beep ( 1500,100 ) 
                ;Beep ( 1500,100 ) 
                
;        EndIf
Until $msg = $GUI_EVENT_CLOSE
发表于 2012-11-12 17:03:32 | 显示全部楼层
本帖最后由 xiehuahere 于 2012-11-12 17:11 编辑

回复 1# 莫小漠

你这就不叫“事件模式”。
事件模式需要 Opt("GUIOnEventMode", 1),并且要为每个控件都用GUICtrlSetOnEvent来注册事件响应函数,GUI窗口用GUISetOnEvent来注册。

不用事件模式也可以的,下面供参考:
#include-once

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("仓位核查", 920, 345, 277, 113)
$list = GUICtrlCreateListView("品种|多单|空单|净头寸", 16, 72, 433, 257)
$Button1 = GUICtrlCreateButton("当前持仓", 96, 16, 89, 25)
$Button2 = GUICtrlCreateButton("Button2", 232, 16, 75, 25)
GUISetState(@SW_SHOW)

Local $flag_Interrupt = 0 ;设置中断标志
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;截获WM_COMMAND消息以处理

Do
        $msg = GUIGetMsg()
        If $msg = $Button1 Then
                $flag_Interrupt = 0
                Do 
                        GUICtrlCreateListViewItem("IF|10|-1|9", $list)
                        Sleep(50)
                Until $flag_Interrupt                
        ElseIf $msg = $Button2 Then
                MsgBox(0, 0, "Interrupted!")                
        EndIf
Until $msg = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        #forceref $hWnd, $Msg
        $LoWord = BitAND($wParam, 0x0000FFFF)
        If $LoWord = $Button2 Then $flag_Interrupt = 1
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND


按Button2中断循环。
 楼主| 发表于 2012-11-12 18:04:46 | 显示全部楼层
回复 2# xiehuahere


    非常感谢。
这样实现了。

如果在加个按钮3,
在按钮1正在循环时,在不使用按钮2的前提下,如何使按钮3点击会触发按钮3的func呢?
发表于 2012-11-13 09:01:40 | 显示全部楼层
本帖最后由 xiehuahere 于 2012-11-13 09:05 编辑

回复 3# 莫小漠


这个跟按钮2的实现是一样的,类似处理就行了。
WM_COMMAND函数里:
If $LoWord = $Button2 Or $LoWord = $Button3 Then $flag_Interrupt = 1


你自己理解一下吧。
 楼主| 发表于 2012-11-13 10:00:10 | 显示全部楼层
回复 4# xiehuahere


   就是把他循环暂停掉。然后在运行其他的。总之循环事件不能跟其他的一起运行。
发表于 2012-11-13 10:04:16 | 显示全部楼层
回复 5# 莫小漠

对,2#的例子看明白了你自然会了,跟Button2的处理还不是一样的嘛
要暂停掉就是在WM_COMMAND里设置中断标志即可。
运行其他的,在Do...Until循环里处理相应的按钮消息即可。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-11 13:35 , Processed in 0.075593 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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