找回密码
 加入
搜索
查看: 2330|回复: 9

GUI在函数执行的时候无法正常退出问题

  [复制链接]
发表于 2009-11-25 00:50:17 | 显示全部楼层 |阅读模式
本帖最后由 vivier001 于 2009-11-25 14:01 编辑

在OnEvent模式下像下面的程序
如果按下确定键也就是执行"OKButton"函数的时候。
当"OKButton"正在执行的时候点击GUI主窗口右上角的退出键好像没反应啊。
程序还是会一直执行不会退出。
也就是按下确定键后,主窗口右上角退出键失效了。

怎样才能在一个函数执行的时候退出这个程序呢?
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; 切换为 OnEvent 模式 
$mainwindow = GUICreate("您好,世界", 200, 100) ; 创建窗口并返回窗口句柄
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ; 设置窗口关闭事件

$okbutton = GUICtrlCreateButton("确定", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton") ; 设置按钮控件单击事件
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; 不做任何事
WEnd

Func OKButton()
        While 1
                sleep(2000)
        WEnd
EndFunc

Func CLOSEClicked()
        Exit
EndFunc
发表于 2009-11-25 01:43:29 | 显示全部楼层
可以使用热键,或
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1) ; 切换为 OnEvent 模式
$mainwindow = GUICreate("您好,世界", 200, 100) ; 创建窗口并返回窗口句柄
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ; 设置窗口关闭事件

$okbutton = GUICtrlCreateButton("确定", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton") ; 设置按钮控件单击事件
GUISetState(@SW_SHOW)

While 1
        Sleep(1000) ; 不做任何事
WEnd

Func OKButton()
        Opt("GUIOnEventMode", 0)
        While 1
                If GUIGetMsg() = -3 Then CLOSEClicked()
        WEnd
EndFunc   ;==>OKButton

Func CLOSEClicked()
        Exit
EndFunc   ;==>CLOSEClicked

评分

参与人数 1金钱 +20 贡献 +2 收起 理由
vivier001 + 20 + 2

查看全部评分

发表于 2009-11-25 01:47:19 | 显示全部楼层
回复 1# vivier001


    建议LZ修改为较详细的标题,便于搜索
 楼主| 发表于 2009-11-25 14:01:08 | 显示全部楼层
可以使用热键,或
afan 发表于 2009-11-25 01:43



    那要是在guigetmsg()后 ,有一个长时间要运行的函数。比如加上一个sleep(200000)而又不想用热键退出,怎么办
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1) ; 切换为 OnEvent 模式
$mainwindow = GUICreate("您好,世界", 200, 100) ; 创建窗口并返回窗口句柄
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ; 设置窗口关闭事件

$okbutton = GUICtrlCreateButton("确定", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton") ; 设置按钮控件单击事件
GUISetState(@SW_SHOW)

While 1
        Sleep(1000) ; 不做任何事
WEnd

Func OKButton()
        Opt("GUIOnEventMode", 0)
        While 1
                If GUIGetMsg() = -3 Then CLOSEClicked()
                sleep(200000);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;这样
        WEnd
EndFunc   ;==>OKButton

Func CLOSEClicked()
        Exit
EndFunc   ;==>CLOSEClicked
发表于 2009-11-25 14:21:06 | 显示全部楼层
本帖最后由 afan 于 2009-11-25 14:22 编辑

长时间要运行动作并不就是sleep(),sleep已经休眠了~
最好有个长时间运行的实例,再看怎样处理比较好~
发表于 2009-11-25 14:21:59 | 显示全部楼层
楼上的几位朋友真是高手!
我也遇到这样的问题!解决了!!谢谢楼主发这个帖!
 楼主| 发表于 2009-11-25 16:06:38 | 显示全部楼层
本帖最后由 vivier001 于 2009-11-25 16:25 编辑
长时间要运行动作并不就是sleep(),sleep已经休眠了~
最好有个长时间运行的实例,再看怎样处理比较好~
afan 发表于 2009-11-25 14:21



好像这样就行了,首先采用的是opt ("GUIOnEventMode",0)模式,
然后点击按钮后设置opt ("GUIOnEventMode",1)然后退出while之前
加上opt ("GUIOnEventMode",0)
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 0)
$mainwindow = GUICreate("您好,世界", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$okbutton = GUICtrlCreateButton("确定", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")
GUISetState(@SW_SHOW)

While 1
        Sleep(1000)
WEnd

Func OKButton()
        Opt("GUIOnEventMode", 1)
        While 1
                If GUIGetMsg() = -3 Then CLOSEClicked()
                                $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
                $oHTTP.Open("post",".......",false)
                $oHTTP.setRequestHeader("Cache-Control", "no-cache")
                $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded") 
                $oHTTP.Send("")
                                If ... Then
                                        opt ("GUIOnEventMode",0)
                                        ExitLoop
                                EndIf
                                
                                $oHTTP.Open("post",".......",false)
                $oHTTP.setRequestHeader("Cache-Control", "no-cache")
                $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded") 
                $oHTTP.Send("")
               If ... Then
                        opt ("GUIOnEventMode",0)
                        ExitLoop
                EndIf
    .........
        WEnd
EndFunc   ;==>OKButton

Func CLOSEClicked()
        Exit
EndFunc   ;==>CLOSEClicked
发表于 2009-11-25 16:22:39 | 显示全部楼层
回复 7# vivier001


    这个我是没办法了,那个延时不好干预,函数内部好像都是等待网页加载完才返回,等高手来帮你解答吧
 楼主| 发表于 2009-11-25 16:29:34 | 显示全部楼层
回复  vivier001


    这个我是没办法了,那个延时不好干预,函数内部好像都是等待网页加载完才返回, ...
afan 发表于 2009-11-25 16:22



    看看7楼我修改过的,差不多能满足条件了,不过好像容易导致程序停止响应,要稍等一会才好
 楼主| 发表于 2009-11-25 16:34:29 | 显示全部楼层
回复  vivier001


    这个我是没办法了,那个延时不好干预,函数内部好像都是等待网页加载完才返回, ...
afan 发表于 2009-11-25 16:22



    看看7楼我修改过的,差不多能满足条件了,不过好像容易导致程序停止响应,要稍等一会才好
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 16:46 , Processed in 0.080482 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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