找回密码
 加入
搜索
查看: 4837|回复: 16

[GUI管理] 事件模式无法退出子函数,请大神指正,内有代码

  [复制链接]
发表于 2014-12-21 00:27:51 | 显示全部楼层 |阅读模式
这段代码运行过后,点了开始就关不掉了,请教一下,哪里有问题?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 444, 267, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("开始", 112, 160, 81, 41, 0)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("暂停", 248, 160, 81, 41, 0)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
While 1
        Sleep(100)
WEnd
Func Button1Click()
        Sleep(900000)
EndFunc
Func Button2Click()
        Exit
EndFunc
Func Form1Close()
Exit
EndFunc
发表于 2014-12-21 01:53:37 | 显示全部楼层
问题就在Sleep(900000)
 楼主| 发表于 2014-12-21 01:58:05 | 显示全部楼层
什么意思?子函数无法中断吗?有其他办法可以将子函数中断不?
发表于 2014-12-21 02:14:47 | 显示全部楼层
本帖最后由 zhouhaijin 于 2014-12-21 02:16 编辑

你sleep这么久就是想写死循环的意思吧
消息模式可以自定义函数里再获取消息判断就行。
事件模式,可以用AdlibRegister的方法

也可以用他总结的方法
http://www.autoitx.com/forum.php ... hlight=%CD%CB%B3%F6
发表于 2014-12-21 02:20:29 | 显示全部楼层
你要是想自定义函数里就sleep(900000),我想退出应该要等900000毫秒才行。
 楼主| 发表于 2014-12-21 02:32:50 | 显示全部楼层
你上边这种方法就可以在我执行等900000秒的时候直接中断它并退出吗?感谢感谢!
发表于 2014-12-21 02:37:09 | 显示全部楼层
不能。。。。。。。。。
发表于 2014-12-21 02:37:12 | 显示全部楼层
不能。。。。。。。。。
发表于 2014-12-21 03:01:17 | 显示全部楼层
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
GUICreate("form1",200,100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

Local $start=GUICtrlCreateButton("开始",10,30,180,20)
GUICtrlSetOnEvent($start,"_While1")
Local $stop=GUICtrlCreateButton("中止",10,50,180,20)
GUICtrlSetOnEvent($stop, "_exit")

GUISetState (@SW_SHOW)

While 1
Sleep(1000)
WEnd

Func _exit ()
        MsgBox (0,"","退出")
        Exit
EndFunc

Func _While1()
        opt ("GUIOnEventMode",0)
        while 1
                Sleep(100)
                $msg = GUIGetMsg()
                Switch $msg
                        Case $stop
                                _exit ()
                EndSwitch
        WEnd
EndFunc
 楼主| 发表于 2014-12-21 07:09:29 | 显示全部楼层
这段代码可以吗?应该也不行吧
发表于 2014-12-22 11:35:40 | 显示全部楼层
#include <Date.au3>
#include <StaticConstants.au3>

Global $bState = True

GUICreate('计时+时间循环', 300, 200)
GUICtrlCreateLabel('系统时间:', 10, 10, 60, 50)
$Time = GUICtrlCreateLabel(_Now(), 70, 10)

$Label1 = GUICtrlCreateLabel('准备就绪', 10, 60, 280, 50, $SS_CENTER)
GUICtrlSetFont(-1, 15, 800, 0, '楷体_GB2312')

$Button1 = GUICtrlCreateButton('开始', 40, 130, 100, 30)
$Button2 = GUICtrlCreateButton('暂停', 160, 130, 100, 30)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1
                        $i = 1
                        AdlibRegister('cont', 1000)
                Case $Button2
                        If $bState = True Then
                                AdlibUnRegister('cont')
                                GUICtrlSetData($Label1, '暂停至' & $i & '秒')
                                GUICtrlSetData($Button2, '继续')
                                $bState = False
                        Else
                                $bState = True
                                GUICtrlSetData($Button2, '暂停')
                                AdlibRegister('cont', 1000)
                        EndIf
        EndSwitch
        
        If _Now() <> GUICtrlRead($Time) Then GUICtrlSetData($Time, _Now())
WEnd

Func cont()
        GUICtrlSetData($Label1, '已开始' & $i & '秒')
        $i += 1
EndFunc   ;==>cont
 楼主| 发表于 2014-12-23 02:35:19 | 显示全部楼层
感谢版主支持!
 楼主| 发表于 2014-12-23 02:40:43 | 显示全部楼层
AdlibRegister这一个我用不了……
发表于 2014-12-23 09:30:01 | 显示全部楼层
回复 13# scared1

你的自定义函数带参数?
 楼主| 发表于 2014-12-26 03:28:48 | 显示全部楼层
我就是复制的你的脚本,但是用不了,提示AdlibRegister未定义。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-29 23:40 , Processed in 0.087533 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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