[已解决]求助! 窗口內 加日時間 秒數也會跳動 該如何做?
本帖最后由 tcpuuu 于 2012-1-22 17:43 编辑求助! 窗口內 加日時間秒數也會跳動該如何做?
GUICreate('TIME',400,560)
;--------------------------------------------------------------------------------------------------
$TIM1 = GUICtrlCreateLabel("",1,502,86,18)
GUICtrlSetData($TIM1,'今天是 ' & @YEAR);---------擷取今年日期
$TIM2 = GUICtrlCreateLabel("-",88,500,8,22)
$TIM3= GUICtrlCreateLabel("",100,502,16,18)
GUICtrlSetData($TIM3,@MON);---------擷取月日期
$TIM4 = GUICtrlCreateLabel("-",118,500,8,22)
$TIM5= GUICtrlCreateLabel("",128,502,16,18)
GUICtrlSetData($TIM5,@MDAY);---------擷取日期
$TIM6= GUICtrlCreateLabel("",148,502,48,18)
GUICtrlSetData($TIM6,@WDAY);---------擷取星期
Select
Case GUICtrlRead($TIM6) = 1
GUICtrlSetData($TIM6,'星期日')
GUICtrlSetColor ($TIM6,0xFF0000)
Case GUICtrlRead($TIM6) = 2
GUICtrlSetData($TIM6,'星期一')
Case GUICtrlRead($TIM6) = 3
GUICtrlSetData($TIM6,'星期二')
Case GUICtrlRead($TIM6) = 4
GUICtrlSetData($TIM6,'星期三')
Case GUICtrlRead($TIM6) = 5
GUICtrlSetData($TIM6,'星期四')
Case GUICtrlRead($TIM6) = 6
GUICtrlSetData($TIM6,'星期五')
Case GUICtrlRead($TIM6) = 7
GUICtrlSetData($TIM6,'星期六')
GUICtrlSetColor ($TIM6,0x008000)
EndSelect
$TIM7 = GUICtrlCreateLabel("",200,502,100,16,0x01)
GUICtrlSetData($TIM7,@HOUR & ":" & @MIN & ":" & @SEC)
For $i = $TIM1 to $TIM7
GUICtrlSetFont($i,12)
Next
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd GUICtrlSetData($TIM7,@HOUR & ":" & @MIN & ":" & @SEC)
放循环里才能跳动哈。。 GUICtrlSetData($TIM7,@HOUR & ":" & @MIN & ":" & @SEC)
放循环里才能跳动哈。。
menfan1 发表于 2012-1-21 12:18 http://www.autoitx.com/images/common/back.gif
WHILL 1
WEND
會整個 一閃一閃 WHILL 1
WEND
會整個 一閃一閃
tcpuuu 发表于 2012-1-21 12:21 http://www.autoitx.com/images/common/back.gif
如果不用太精确的话, 用 AdlibRegister .
如果想比较精确的话请参考帮助文档的 _TicksToTime, 它带了一个例子! 我建议单独开启一个进程去注册AdlibRegister更新秒数,否则在运行其他的函数的时候会卡住不动 直到其他函数运行完毕 回复 5# love5173
請問 LOVE8173大大
這個怎麼用?
可以說詳細嗎? 回复 6# tcpuuu
http://www.autoitx.com/forum.php?mod=viewthread&tid=475&highlight=%B6%E0%BD%F8%B3%CC这里是多进程相关的信息,需要自己下
#include "CoProc.au3"
$Pidmsgb = _CoProc("newline")
func newline()
AdlibRegister ( "dataup" [, 时间] )
endfunc
funcdataup()
更新时间到控件
endfunc
大概是这样的 本帖最后由 love5173 于 2012-1-21 15:20 编辑
回复 6# tcpuuu
写的比较粗糙,这个函数我也不怎么用,用的时候发现不怎么好用,不知道是不是不会用的原因
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_outfile=..\..\789798789.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include "CoProc.au3"
GUICreate('TIME',400,560)
Global $TIM7,$gi_CoProcParentli
;--------------------------------------------------------------------------------------------------
$TIM1 = GUICtrlCreateLabel("",1,502,86,18)
GUICtrlSetData($TIM1,'今天是' & @YEAR);---------擷取今年日期
$TIM2 = GUICtrlCreateLabel("-",88,500,8,22)
$TIM3= GUICtrlCreateLabel("",100,502,16,18)
GUICtrlSetData($TIM3,@MON);---------擷取月日期
$TIM4 = GUICtrlCreateLabel("-",118,500,8,22)
$TIM5= GUICtrlCreateLabel("",128,502,16,18)
GUICtrlSetData($TIM5,@MDAY);---------擷取日期
$TIM6= GUICtrlCreateLabel("",148,502,48,18)
GUICtrlSetData($TIM6,@WDAY);---------擷取星期
Select
Case GUICtrlRead($TIM6) = 1
GUICtrlSetData($TIM6,'星期日')
GUICtrlSetColor ($TIM6,0xFF0000)
Case GUICtrlRead($TIM6) = 2
GUICtrlSetData($TIM6,'星期一')
Case GUICtrlRead($TIM6) = 3
GUICtrlSetData($TIM6,'星期二')
Case GUICtrlRead($TIM6) = 4
GUICtrlSetData($TIM6,'星期三')
Case GUICtrlRead($TIM6) = 5
GUICtrlSetData($TIM6,'星期四')
Case GUICtrlRead($TIM6) = 6
GUICtrlSetData($TIM6,'星期五')
Case GUICtrlRead($TIM6) = 7
GUICtrlSetData($TIM6,'星期六')
GUICtrlSetColor ($TIM6,0x008000)
EndSelect
$TIM7 = GUICtrlCreateLabel("",200,502,100,16,0x01)
GUICtrlSetData($TIM7,@HOUR & ":" & @MIN & ":" & @SEC)
$ch=_CoProc("updata")
For $i = $TIM1 to $TIM7
GUICtrlSetFont($i,12)
Next
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd
Func updata()
While 1
If Not WinExists("TIME","") Then Exit
ControlSetText("TIME","","Static7",@HOUR & ":" & @MIN & ":" & @SEC)
WEnd
EndFunc #include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;变量必须先声明后使用
Opt("MustDeclareVars", 1)
;创建GUI
Global $gu_Form1 = GUICreate("时间日期", 220, 52, -1, -1)
Global $gu_Label1 = GUICtrlCreateLabel("", 0, 16, 220, 17, $SS_CENTER)
;运行主函数
_Clock_Main()
Exit 1
;程序主函数
Func _Clock_Main()
;初始化日期、周几、时间值
_Clock_RefeshClock()
;显示GUI
GUISetState(@SW_SHOW)
;每隔一秒刷新日期、周几、时间值
AdlibRegister("_Clock_RefeshClock", 1000)
Local $nMsg
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
EndFunc ;==>_Clock_Main
;刷新日期、周几、时间值
Func _Clock_RefeshClock()
Local $Data = _Clock_Date() ;获取日期
Local $Time = _Clock_Time() ;获取时间
Local $Wday = _Clock_Wday() ;获取周几
;显示时钟信息
GUICtrlSetData($gu_Label1, $Data & " " & $Wday & " " & $Time)
EndFunc ;==>_Clock_RefeshClock
;获取日期
Func _Clock_Date()
Return @YEAR & "年" & @MON & "月" & @MDAY & "日"
EndFunc ;==>_Clock_Date
;获取时间
Func _Clock_Time()
Return @HOUR & ":" & @MIN & ":" & @SEC
EndFunc ;==>_Clock_Time
;获取周几
Func _Clock_Wday()
Local $a_Wday
;根据@WDAY的值(1~7)获取“星期x”的值
Switch @WDAY
Case 1
$a_Wday = "星期天"
Case 2
$a_Wday = "星期一"
Case 3
$a_Wday = "星期二"
Case 4
$a_Wday = "星期三"
Case 5
$a_Wday = "星期四"
Case 6
$a_Wday = "星期五"
Case 7
$a_Wday = "星期六"
EndSwitch
Return $a_Wday
EndFunc ;==>_Clock_Wday
回复 9# 零度深蓝
功能上没有错误,只是怕楼主要加一些其他的函数,会把这个函数卡主的,以前我以为这个东西可以模拟多线程的,可以后来我知道我错了 Switch @WDAY
Case 1
$a_Wday = "星期天"
Case 2
$a_Wday = "星期一"
Case 3
$a_Wday = "星期二"
Case 4
$a_Wday = "星期三"
Case 5
$a_Wday = "星期四"
Case 6
$a_Wday = "星期五"
Case 7
$a_Wday = "星期六"
EndSwitch
Return $a_Wday
-------------------------------------------------------------------------------
以上這段 如果星期六要變綠色的
星期日要變紅色的 怎麼改? 为一个时间就是加多一个线程?感觉1秒刷新一次差不多了。。
除了网络问题,一般功能 或函数都可以在1秒内完全 AdlibRegister用这个是最好的!不影响主程序的消息循环! 噢,又学会了一样。 噢,又学会了一样。
页:
[1]
2