sky808 发表于 2009-11-8 20:15:24

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

本帖最后由 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

试试设置快捷键退出呢?

sky808 发表于 2009-11-8 21:27:30

这样就没意义了.
本身就是要在窗口上按钮实现的功能.

sky808 发表于 2009-11-9 07:27:40

希望高手能帮忙回答下,多谢!

C.L 发表于 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

sky808 发表于 2009-11-9 08:37:52

嗯嗯,多谢!
请问上面的 GUICtrlSetOnEvent(-1,"_Exit") 的 -1 什么含义呢?
多谢!

sky808 发表于 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

麻烦高手们了~~~

sky808 发表于 2009-11-9 10:23:42

有没有高手能回答下呢,等着用呢

C.L 发表于 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

C.L 发表于 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

sky808 发表于 2009-11-9 19:24:59

多谢多谢,我来看看!
页: [1]
查看完整版本: GUI如何中止调用未退出函数的程序