laomeng 发表于 2014-12-8 23:53:28

[已解决]如何使鼠标拖动窗体倒计时不停止?

本帖最后由 laomeng 于 2014-12-9 21:46 编辑

在论坛上看到大侠写的倒计时,但是鼠标点到窗体上方或者移动窗体的时候 倒计时会停止,如何实现不让它停止呢?谢谢 指教!!!#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $time = 30
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("倒计时测试窗口", 350, 172, 193, 125)
$Label1 = GUICtrlCreateLabel("30秒后将进入主程序!", 56, 32, 232, 28)
GUICtrlSetFont(-1, 18, 400, 0, "楷体_GB2312")
$Progress1 = GUICtrlCreateProgress(8, 88, 333, 17)
$Button1 = GUICtrlCreateButton("确定(&Y)", 53, 128, 73, 25, 0)
$Button2 = GUICtrlCreateButton("退出(&X)", 210, 128, 73, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibEnable("_timer", 1000)
While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE, $Button2
                        Exit
                Case $Button1
                        ExitLoop
      EndSwitch
      If $time <= 0 Then ExitLoop
WEnd
main()
Exit

Func _timer()
      $time -= 1
      GUICtrlSetData($Label1, $time & "秒后将进入主程序!")
      GUICtrlSetData($Progress1, (30 - $time) / 0.3)
      If $time <= 0 Then AdlibDisable()
EndFunc   ;==>_timer

Func main()
      MsgBox(0, 'test', '倒计时结束,进入主程序.', 10)
      ;以下为主程序
EndFunc   ;==>main

austere 发表于 2014-12-9 08:51:45

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $time = 30
#Region ### START Koda GUI section ### Form=
AdlibRegister("time")
$time1 = TimerInit()
$Form1 = GUICreate("倒计时测试窗口", 350, 172, 193, 125)
$Label1 = GUICtrlCreateLabel("30秒后将进入主程序!", 56, 32, 232, 28)
GUICtrlSetFont(-1, 18, 400, 0, "楷体_GB2312")
$Progress1 = GUICtrlCreateProgress(8, 88, 333, 17)
$Button1 = GUICtrlCreateButton("确定(&Y)", 53, 128, 73, 25, 0)
$Button2 = GUICtrlCreateButton("退出(&X)", 210, 128, 73, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE, $Button2
                        AdlibUnRegister("time")
                        Exit
                Case $Button1
                        ExitLoop
        EndSwitch
        If $time = 1 Then ExitLoop
WEnd
main()
Exit

Func time()
          If TimerDiff($time1) > 1000 Then
                GUICtrlSetData($Label1, $time & "秒后将进入主程序!")
                GUICtrlSetData($Progress1, (30 - $time) / 0.3)
                $time = $time - 1
                $time1 = TimerInit()
                EndIf
EndFunc   ;==>time

Func main()
        MsgBox(0, 'test', '倒计时结束,进入主程序.', 10)
        ;以下为主程序
EndFunc   ;==>main

laomeng 发表于 2014-12-9 10:14:12

回复 2# austere


    谢谢但是 还是一样会停止

austere 发表于 2014-12-9 10:16:44

回复 3# laomeng


    你的意思是窗口没有激活,就暂停进度条吗?

deaph 发表于 2014-12-9 10:26:18

学习了,感谢分享!!

laomeng 发表于 2014-12-9 10:28:30

回复 4# austere


    不是。
是在倒计时开始后用鼠标点到窗体上方拖动的时候读秒会停止,有什么办法 使它 不停止呢

chzj589 发表于 2014-12-9 10:37:51

回复 3# laomeng


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $time = 30, $time1, $Label1, $Progress1
GUIa()
While 1
        Sleep(1000)
WEnd
Func GUIa()
        ;AdlibRegister("time")
        $time1 = TimerInit()
        $Form1 = GUICreate("倒计时测试窗口", 350, 172, 193, 125)
        GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
        $Label1 = GUICtrlCreateLabel("30秒后将进入主程序!", 56, 32, 232, 28)
        GUICtrlSetFont(-1, 18, 400, 0, "楷体_GB2312")
        $Progress1 = GUICtrlCreateProgress(8, 88, 333, 17)
        $Button1 = GUICtrlCreateButton("确定(&Y)", 53, 128, 73, 25, 0)
        GUICtrlSetOnEvent($Button1, "time")
        $Button2 = GUICtrlCreateButton("退出(&X)", 210, 128, 73, 25, 0)
        GUICtrlSetOnEvent($Button2, "Form1Close")
        GUISetState(@SW_SHOW)
EndFunc   ;==>GUIaProg
Func time()
        AdlibRegister("time")
        If TimerDiff($time1) > 1000 Then
                GUICtrlSetData($Label1, $time & "秒后将进入主程序!")
                GUICtrlSetData($Progress1, (30 - $time) / 0.3)
                $time = $time - 1
                $time1 = TimerInit()
        EndIf
        If $time = 0 Then
                main()
        EndIf       
EndFunc   ;==>time
Func main()
        MsgBox(0, 'test', '倒计时结束,进入主程序.', 1)
        ;以下为主程序
        Form1Close()
EndFunc   ;==>main
Func Form1Close()       
        Exit
EndFunc   ;==>Form1Close

laomeng 发表于 2014-12-9 11:01:09

回复 7# chzj589


    谢谢你的解答,但还是没有解决我的问题

鼠标 拖动窗体读秒还是会停止。 我记得之前有看到过 实现的方法, 现在找不到了

austere 发表于 2014-12-9 11:24:42

明白你的意思了,你按了标题栏程序会暂停的~所以用winmove来实现就可以了~

laomeng 发表于 2014-12-9 11:36:52

回复 9# austere


    请指教 谢!

afan 发表于 2014-12-9 12:24:52

用定时器
#Include <Timers.au3>
_Timer_SetTimer($hWnd [, $iElapse = 250 [, $sTimerFunc = "" [, $iTimerID = -1]]])

austere 发表于 2014-12-9 15:59:23

Afan的办法不错,试过可行~

laomeng 发表于 2014-12-9 21:45:21

回复 11# afan


    多谢提醒已解决

laomeng 发表于 2014-12-9 21:45:45

回复 12# austere


    已OK
页: [1]
查看完整版本: [已解决]如何使鼠标拖动窗体倒计时不停止?