『已解决』gui可否设置超时?
本帖最后由 aassddffgg961 于 2013-3-25 09:48 编辑本人菜鸟,做了一个窗口,想添加一个超时,如果30秒没操作就用自动点确定,如果有鼠标或者键盘输入时窗口的计时就取消。不知道有没有办法?万分感谢。#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
Example1()
Func Example1()
Local $msg,$Button_1,$Button_2,$open,$answer
GUICreate("12333",650,200,-1,-1)
GUISetFont(25)
GUICtrlCreateLabel("456789",3,5,650,30)
$open=GUICtrlCreateInput("1234",100,70, 300, 35)
GUISetFont(10)
$Button_1 =GUICtrlCreateButton("确定",120, 115, 70, 40)
GUICtrlSetState(-1, $GUI_FOCUS)
$Button_2 =GUICtrlCreateButton("取消", 260,115,70,40)
GUISetState()
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Button_2
Exit
Case $msg = $Button_1
$answer=GUICtrlRead($open)
FileDelete(@ScriptDir&"\test.txt")
FileOpen("test.txt", 1)
FileWrite("test.txt","321")
FileWrite("test.cmd",$answer)
ExitLoop
EndSelect
WEnd
GUIDelete()
EndFunc Global $time = 10
GUICreate('12333', 650, 200)
GUISetFont(25)
GUICtrlCreateLabel('456789', 3, 5, 650, 30)
$open = GUICtrlCreateInput('1234', 100, 70, 300, 35)
GUISetFont(10)
$Button_1 = GUICtrlCreateButton('确定(' & $time & ')', 120, 115, 70, 40)
GUICtrlSetState(-1, 0x100) ;$GUI_FOCUS = 0x100
$Button_2 = GUICtrlCreateButton('取消', 260, 115, 70, 40)
GUISetState()
AdlibRegister("_timer", 1000)
While 1
Switch GUIGetMsg()
Case -3
Exit
Case -7, -9
AdlibUnRegister()
GUICtrlSetData($Button_1, '确定')
Case $Button_2
Exit
Case $Button_1
_Go()
EndSwitch
WEnd
Func _timer()
$time -= 1
GUICtrlSetData($Button_1, '确定(' & $time & ')')
If $time <= 0 Then
AdlibUnRegister()
_Go()
EndIf
EndFunc ;==>_timer
Func _Go()
$answer = GUICtrlRead($open)
FileWrite(@ScriptDir & '\test.txt','321' & @CRLF)
FileWrite(@ScriptDir & '\test.cmd', $answer & @CRLF)
Exit
EndFunc ;==>_Go 本帖最后由 liongodmien 于 2013-3-13 14:23 编辑
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
Example1()
Func Example1()
Local $msg, $Button_1, $Button_2, $open, $answer, $T, $L, $R, $Flag
$GUI = GUICreate("Test", 650, 200, -1, -1)
GUISetFont(25)
GUICtrlCreateLabel("456789", 3, 5, 650, 30)
$open = GUICtrlCreateInput("1234", 100, 70, 300, 35)
GUISetFont(10)
$Button_1 = GUICtrlCreateButton("确定", 120, 115, 70, 40)
GUICtrlSetState(-1, $GUI_FOCUS)
$Button_2 = GUICtrlCreateButton("取消", 260, 115, 70, 40)
GUISetState()
GUISetState(@SW_SHOW)
$L = StringLen(GUICtrlRead($open))
$T = TimerInit()
While 1
$msg = GUIGetMsg()
If ($L <> StringLen(GUICtrlRead($open))) Then
$L = StringLen(GUICtrlRead($open))
$R = TimerInit()
$Flag = 0
WinSetTitle($GUI, "", "Test")
ElseIf (TimerDiff($T) > 3E4) Then
$msg = $Button_1
ElseIf (TimerDiff($R) > 1E4) Then
$T = TimerInit()
$R = TimerInit() + 9E9
$Flag = 1
ElseIf $Flag Then
WinSetTitle($GUI, "", "选择剩余" & Int((3E4 - TimerDiff($T)) / 1E3) & "秒")
Else
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $Button_2
MsgBox(0,0,"点了按钮2")
Exit
Case $Button_1
MsgBox(0,0,"点了按钮1")
ExitLoop
EndSwitch
EndIf
WEnd
GUIDelete()
EndFunc ;==>Example1
回复 2# afan
你好,谢谢你的帮助,但我复杂你的代码想演示下为何会这样?显示“AdlibRegister”错误?
回复 3# liongodmien
你好,谢谢你的帮助,但好像陷入死循环了,无论我点取消还是确定都在重新计时,不会下一步。 回复afan
你好,谢谢你的帮助,但我复杂你的代码想演示下为何会这样?显示“AdlibRegister”错 ...
aassddffgg961 发表于 2013-3-13 15:04 http://www.autoitx.com/images/common/back.gif
你的 Autoit3 版本过低。需使用 3.3.3.1 以上版本。
或将 “AdlibRegister” 替换为 “AdlibEnable”、“AdlibUnRegister” 替换为 “AdlibDisable”即可。 回复 6# afan
谢谢A版,如果我要运行两个窗口,一个窗口完成后再显示第二个窗口,第二个也带有定时,定时到还是选择默认设置要怎么搞?如下 #include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
Example1()
Example2()
Func Example1()
Local $msg,$Button_1,$Button_2,$open,$answer
GUICreate("123",650,200,-1,-1)
GUISetFont(25)
GUICtrlCreateLabel("654879",3,5,650,30)
$open=GUICtrlCreateInput("0101",100,70, 300, 35)
GUISetFont(10)
$Button_1 =GUICtrlCreateButton("确定",120, 115, 70, 40)
GUICtrlSetState(-1, $GUI_FOCUS)
$Button_2 =GUICtrlCreateButton("取消", 260,115,70,40)
GUISetState()
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Button_2
Exit
Case $msg = $Button_1
$answer=GUICtrlRead($open)
FileDelete(@ScriptDir&"\test.txt")
FileOpen("test.txt", 1)
FileWrite("test.txt","321")
FileWrite("test.txt",$answer)
ExitLoop
EndSelect
WEnd
GUIDelete()
EndFunc;==>Example
Func Example2()
Local $msg2,$Button_3,$Button_4,$open2,$answer2
GUICreate("456",600,200,-1,-1)
GUISetFont(25)
GUICtrlCreateLabel("987",3,5,650,30)
$open2=GUICtrlCreateInput("abc",100,70, 300, 35)
GUISetFont(10)
$Button_3 =GUICtrlCreateButton("确定", 120, 115, 70, 40)
GUICtrlSetState(-1, $GUI_FOCUS)
$Button_4 =GUICtrlCreateButton("取消", 260,115,70,40)
GUISetState()
GUISetState(@SW_SHOW)
While 1
$msg2= GUIGetMsg()
Select
Case $msg2= $GUI_EVENT_CLOSE
Exit
Case $msg2= $Button_3
$answer2=GUICtrlRead($open2)
FileOpen("test.txt", 1)
FileWrite("test.txt"," 666")
FileWrite("test.txt",$answer2)
ExitLoop
Case $msg2= $Button_4
Exit
EndSelect
WEnd
GUIDelete()
EndFunc 呜呜。。。球解决。。。不然指个方向也行,提个示例啥的。。。。。 回复 3# liongodmien
跪求”liongodmien“修复代码。我想学习下。谢谢。 狮子难得上来一趟…#include <GUIConstantsEx.au3>
Example1()
Func Example1()
Local $msg, $Button_1, $Button_2, $open, $answer, $T, $L, $R, $Flag = 1
$GUI = GUICreate("Test", 650, 200, -1, -1)
GUISetFont(25)
GUICtrlCreateLabel("456789", 3, 5, 650, 30)
$open = GUICtrlCreateInput("1234", 100, 70, 300, 35)
GUISetFont(10)
$Button_1 = GUICtrlCreateButton("确定", 120, 115, 70, 40)
GUICtrlSetState(-1, $GUI_FOCUS)
$Button_2 = GUICtrlCreateButton("取消", 260, 115, 70, 40)
GUISetState()
GUISetState(@SW_SHOW)
$L = GUICtrlRead($open)
$T = TimerInit()
While 1
$msg = GUIGetMsg()
If ($L <> GUICtrlRead($open)) Then
$L = GUICtrlRead($open)
$R = TimerInit()
$Flag = 0
WinSetTitle($GUI, "", "Test")
ElseIf (TimerDiff($T) > 3E4) Then
$msg = $Button_1
ElseIf Not $Flag And (TimerDiff($R) > 1E4) Then
$T = TimerInit()
$R = $T + 9E9
$Flag = 1
ElseIf $Flag Then
WinSetTitle($GUI, "", "选择剩余" & Int((3E4 - TimerDiff($T)) / 1E3) & "秒")
EndIf
Switch $msg
Case -3
Exit
Case $Button_2
MsgBox(0, 0, "点了按钮2")
Exit
Case $Button_1
MsgBox(0, 0, "点了按钮1")
ExitLoop
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Example1
好久没见狮子了. {:face (239):}谢谢A版。 新手来学习
页:
[1]