本帖最后由 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中断循环。 |