找回密码
 加入
搜索
查看: 5165|回复: 11

[AU3基础] [已解决]程序中含有循环代码,GUI点击关闭按钮无效!

  [复制链接]
发表于 2010-5-17 21:12:08 | 显示全部楼层 |阅读模式
本帖最后由 xkowen 于 2010-5-19 11:23 编辑

点击按钮后会进入一个循环,但是主窗口无法关闭,请高人指定如何做到点击按钮后进入一事件循环,而且可以点击关闭按钮关闭程序。谢谢!
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 244, 104, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Button1 = GUICtrlCreateButton("开始", 80, 64, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("时间:", 24, 32, 40, 17)
$Input1 = GUICtrlCreateInput("10", 64, 24, 121, 21)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Button1,"Button")
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(1000)
WEnd

Func CLOSEClicked()
        Exit
EndFunc

Func Button()
        $t=GUICtrlRead($Input1)
        While 1
                Sleep(1000*$t)
                MsgBox(0,"","OK")
        WEnd
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-5-17 21:50:46 | 显示全部楼层
global $msg= guigetmsg()
...
adlibregister('exitthis')
#EndRegion ### END Koda GUI section ###
...

func exitthis()
  if $msg= -3 then exit
endfunc
试试看,不知道行不行
发表于 2010-5-17 22:05:38 | 显示全部楼层
Sleep(1000*$t),楼主理解这句话了吗?实在不理解,删了它再试试吧
发表于 2010-5-18 00:54:31 | 显示全部楼层
我也遇到同样过的问题,函数不运行结束其它按键就不能用。期待解答
 楼主| 发表于 2010-5-18 02:15:25 | 显示全部楼层
Sleep(1000*$t),楼主理解这句话了吗?实在不理解,删了它再试试吧
shqf 发表于 2010-5-17 22:05

使用sleep(1000*$t)是因为这个地方我要放一部分代码,sleep仅代表执行这段代码所需的时间,为了方便高手们指点,所以省略了。请指点,谢谢!
发表于 2010-5-18 08:50:10 | 显示全部楼层
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 244, 104, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Button1 = GUICtrlCreateButton("开始", 80, 64, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("时间:", 24, 32, 40, 17)
$Input1 = GUICtrlCreateInput("10", 64, 24, 121, 21)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Button1,"Button")
#EndRegion ### END Koda GUI section ###
$pause = True
While 1
        $t=GUICtrlRead($Input1)
        If $pause = False Then
                        While 1
                                Sleep(1000*$t)
                                
                                MsgBox(0,"","OK")
                                $pause=True
                        WEnd        
        EndIf
        
WEnd

Func CLOSEClicked()
        Exit
EndFunc

Func Button()
        $pause=False
EndFunc
这是楼主想要的代码吗?

评分

参与人数 1金钱 +10 收起 理由
xkowen + 10 乐于助人

查看全部评分

发表于 2010-5-18 08:56:36 | 显示全部楼层
利用“用户预定义的函数”的优先权,来关闭进入循环的代码,这可能不是你想要的。但如果在这段代码中是可行的。
 楼主| 发表于 2010-5-18 09:29:11 | 显示全部楼层
回复 6# chnlikang
这个解决方法不错,又学到了一招。谢谢!想问问还有没有其他实现的方法?
 楼主| 发表于 2010-5-18 09:31:56 | 显示全部楼层
我也遇到同样过的问题,函数不运行结束其它按键就不能用。期待解答
chnlikang 发表于 2010-5-18 00:54

六楼已有解决方法,可以参考一下!
发表于 2010-5-18 11:55:54 | 显示全部楼层
6楼的代码会陷入二级while循环中不跳出来。 看这个。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $Flg=False
Local $t=0
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 244, 104, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Button1 = GUICtrlCreateButton("开始", 80, 64, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("时间:", 24, 32, 40, 17)
$Input1 = GUICtrlCreateInput("10", 64, 24, 121, 21)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Button1,"Button")
#EndRegion ### END Koda GUI section ###

While 1
        If $Flg=True Then
                Sleep(1000*$t)
                MsgBox(0,"","OK")
        Else
                Sleep(200)
        EndIf
WEnd
Func CLOSEClicked()
        Exit
EndFunc
Func Button()
        $t=GUICtrlRead($Input1)
                $Flg=True
EndFunc
发表于 2010-5-19 10:22:46 | 显示全部楼层
不错高手如云,我的学习之路还很漫长。
 楼主| 发表于 2010-5-19 11:19:21 | 显示全部楼层
回复 10# lanfengc
谢谢,值得学习。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-28 17:44 , Processed in 0.086956 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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