找回密码
 加入
搜索
查看: 8342|回复: 13

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

  [复制链接]
发表于 2014-12-8 23:53:28 | 显示全部楼层 |阅读模式
本帖最后由 laomeng 于 2014-12-9 21:46 编辑

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

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

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

  35. Func main()
  36.         MsgBox(0, 'test', '倒计时结束,进入主程序.', 10)
  37.         ;以下为主程序
  38. EndFunc   ;==>main
复制代码
发表于 2014-12-9 08:51:45 | 显示全部楼层
  1. #include <ButtonConstants.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <ProgressConstants.au3>
  4. #include <StaticConstants.au3>
  5. #include <WindowsConstants.au3>

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

  18. While 1
  19.         $nMsg = GUIGetMsg()
  20.         Switch $nMsg
  21.                 Case $GUI_EVENT_CLOSE, $Button2
  22.                         AdlibUnRegister("time")
  23.                         Exit
  24.                 Case $Button1
  25.                         ExitLoop
  26.         EndSwitch
  27.         If $time = 1 Then ExitLoop
  28. WEnd
  29. main()
  30. Exit

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

  39. Func main()
  40.         MsgBox(0, 'test', '倒计时结束,进入主程序.', 10)
  41.         ;以下为主程序
  42. EndFunc   ;==>main
复制代码
 楼主| 发表于 2014-12-9 10:14:12 | 显示全部楼层
回复 2# austere


    谢谢  但是 还是一样  会停止
发表于 2014-12-9 10:16:44 | 显示全部楼层
回复 3# laomeng


    你的意思是窗口没有激活,就暂停进度条吗?
发表于 2014-12-9 10:26:18 | 显示全部楼层
学习了,感谢分享!!
 楼主| 发表于 2014-12-9 10:28:30 | 显示全部楼层
回复 4# austere


    不是。
是在倒计时开始后  用鼠标点到窗体上方拖动的时候  读秒会停止,有什么办法 使它 不停止呢
发表于 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
 楼主| 发表于 2014-12-9 11:01:09 | 显示全部楼层
回复 7# chzj589


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

鼠标 拖动窗体  读秒还是会停止。 我记得之前有看到过 实现的方法, 现在找不到了
发表于 2014-12-9 11:24:42 | 显示全部楼层
明白你的意思了,你按了标题栏程序会暂停的~  所以用winmove来实现就可以了~
 楼主| 发表于 2014-12-9 11:36:52 | 显示全部楼层
回复 9# austere


    请指教 谢!
发表于 2014-12-9 12:24:52 | 显示全部楼层
用定时器
#Include <Timers.au3>
_Timer_SetTimer($hWnd [, $iElapse = 250 [, $sTimerFunc = "" [, $iTimerID = -1]]])
发表于 2014-12-9 15:59:23 | 显示全部楼层
Afan的办法不错,试过可行~
 楼主| 发表于 2014-12-9 21:45:21 | 显示全部楼层
回复 11# afan


    多谢提醒  已解决
 楼主| 发表于 2014-12-9 21:45:45 | 显示全部楼层
回复 12# austere


    已OK
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2026-9-22 08:58 , Processed in 0.074424 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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