找回密码
 加入
搜索
查看: 5012|回复: 12

[AU3基础] 『已解决』gui可否设置超时?

  [复制链接]
发表于 2013-3-13 13:14:46 | 显示全部楼层 |阅读模式
本帖最后由 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 
发表于 2013-3-13 14:16:45 | 显示全部楼层
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

评分

参与人数 1金钱 +10 收起 理由
aassddffgg961 + 10 谢谢帮助

查看全部评分

发表于 2013-3-13 14:21:44 | 显示全部楼层
本帖最后由 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

评分

参与人数 1金钱 +20 收起 理由
aassddffgg961 + 20 谢谢帮助

查看全部评分

 楼主| 发表于 2013-3-13 15:04:40 | 显示全部楼层
回复 2# afan


    你好,谢谢你的帮助,但我复杂你的代码想演示下为何会这样?显示“AdlibRegister”错误?

本帖子中包含更多资源

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

×
 楼主| 发表于 2013-3-13 15:05:48 | 显示全部楼层
回复 3# liongodmien


    你好,谢谢你的帮助,但好像陷入死循环了,无论我点取消还是确定都在重新计时,不会下一步。
发表于 2013-3-13 15:20:45 | 显示全部楼层
回复  afan


    你好,谢谢你的帮助,但我复杂你的代码想演示下为何会这样?显示“AdlibRegister”错 ...
aassddffgg961 发表于 2013-3-13 15:04



    你的 Autoit3 版本过低。需使用 3.3.3.1 以上版本。
或将 “AdlibRegister” 替换为 “AdlibEnable”、“AdlibUnRegister” 替换为 “AdlibDisable”即可。

评分

参与人数 1金钱 +10 收起 理由
aassddffgg961 + 10 谢谢帮助

查看全部评分

 楼主| 发表于 2013-3-14 18:30:02 | 显示全部楼层
回复 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    
 楼主| 发表于 2013-3-17 18:20:25 | 显示全部楼层
呜呜。。。球解决。。。不然指个方向也行,提个示例啥的。。。。。
 楼主| 发表于 2013-3-24 16:06:46 | 显示全部楼层
回复 3# liongodmien


   跪求”liongodmien“修复代码。我想学习下。谢谢。
发表于 2013-3-24 17:18:46 | 显示全部楼层
狮子难得上来一趟…
#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

评分

参与人数 1金钱 +20 收起 理由
aassddffgg961 + 20

查看全部评分

发表于 2013-3-25 07:03:40 | 显示全部楼层
好久没见狮子了.
 楼主| 发表于 2013-3-25 09:47:26 | 显示全部楼层
谢谢A版。
发表于 2013-3-25 16:24:26 | 显示全部楼层
新手来学习
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 09:29 , Processed in 0.105385 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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