找回密码
 加入
搜索
查看: 3234|回复: 10

GUI如何中止调用未退出函数的程序

[复制链接]
发表于 2009-11-8 20:15:24 | 显示全部楼层 |阅读模式
本帖最后由 sky808 于 2009-11-9 07:26 编辑

请问程序在调用函数内部工作时消息循环如何中止执行并退出呢?

如:
GUICreate("form1",200,100)
Local $stop=GUICtrlCreateButton("中止",20,180)

_While1()  ;调用函数死循环

While 1
Switch GUIGetMsg()
case $stop
exit
EndSwitch
WEnd

Func _While1()
While 1
Sleep(1000)
WEnd
EndFunc

请问程序如何能单击中止时就能退出死循环呢?

多谢高手回答!
发表于 2009-11-8 20:51:57 | 显示全部楼层
试试设置快捷键退出呢?
 楼主| 发表于 2009-11-8 21:27:30 | 显示全部楼层
这样就没意义了.
本身就是要在窗口上按钮实现的功能.
 楼主| 发表于 2009-11-9 07:27:40 | 显示全部楼层
希望高手能帮忙回答下,多谢!
发表于 2009-11-9 08:18:41 | 显示全部楼层
用Opt("GUIOnEventMode", 1)
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
GUICreate("form1",200,100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
Local $stop=GUICtrlCreateButton("中止",10,50,180,20)
GUICtrlSetOnEvent(-1, "_exit")

GUISetState (@SW_SHOW)
_While1()  ;调用函数死循环

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

Func _While1()
While 1
Sleep(1000)
WEnd
EndFunc
 楼主| 发表于 2009-11-9 08:37:52 | 显示全部楼层
嗯嗯,多谢!
请问上面的 GUICtrlSetOnEvent(-1,"_Exit") 的 -1 什么含义呢?
多谢!
 楼主| 发表于 2009-11-9 08:46:42 | 显示全部楼层
但是用事件发送调用的死循环函数就不行了.

如:  

#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()
while 1
Sleep(1000)
WEnd
EndFunc

麻烦高手们了~~~
 楼主| 发表于 2009-11-9 10:23:42 | 显示全部楼层
有没有高手能回答下呢,等着用呢
发表于 2009-11-9 13:01:40 | 显示全部楼层
在循环体内用Opt("GUIOnEventMode", 0)
#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

评分

参与人数 2金钱 +11 贡献 +10 收起 理由
sky808 + 1 十分感谢!
afan + 10 + 10

查看全部评分

发表于 2009-11-9 13:10:51 | 显示全部楼层
如果不要脚本退出,只返回,可以这样写:
Func _While1()
       opt ("GUIOnEventMode",0)
        while 1
               Sleep(100)
                $msg = GUIGetMsg()
                Switch $msg
                        Case $stop
                           opt ("GUIOnEventMode",1)
                   ExitLoop
                EndSwitch
        WEnd
EndFunc

评分

参与人数 1金钱 +10 贡献 +10 收起 理由
afan + 10 + 10

查看全部评分

 楼主| 发表于 2009-11-9 19:24:59 | 显示全部楼层
多谢多谢,我来看看!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 17:38 , Processed in 0.071575 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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