Показать полную графическую версию : [решено] Создание авто опроса событий GUI
IronOleg
09-11-2009, 19:08
Вот есть прога:
#include <Date.au3>
#include <GUIConstants.au3>
GUICreate("Дата и Время", 300, 100)
$datetime = GUICtrlCreateLabel("Текущая дата и время: " & _Now(), 1, 50)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $datetime
GUICtrlSetData($datetime, "Текущая дата и время: " & _Now())
Case $msg = $GUI_EVENT_CLOSE
MsgBox(0, "GUI", "Выход...")
ExitLoop
EndSelect
WEnd
Мне нужно чтобы время обновлялось не при нажатии, а само. ТО есть были бы часы как встроенные в Windows XP. Помогите плиз.
#include <Date.au3>
#include <GUIConstants.au3>
GUICreate("Дата и Время", 300, 100)
$datetime = GUICtrlCreateLabel("Текущая дата и время: " & _Now(), 1, 50)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
MsgBox(0, "GUI", "Выход...")
ExitLoop
EndSelect
GUICtrlSetData($datetime, "Текущая дата и время: " & _Now())
WEnd
Можно так.
А лучше так:
#include <Date.au3>
#include <GUIConstants.au3>
GUICreate("Дата и Время", 300, 100)
$datetime = GUICtrlCreateLabel("Текущая дата и время: " & _Now(), 1, 50)
GUISetState(@SW_SHOW)
AdlibEnable("Time",1000)
While 1
$msg = GUIGetMsg()
Select
Case $GUI_EVENT_CLOSE
AdlibDisable()
Exit
EndSelect
WEnd
Func Time()
GUICtrlSetData($datetime, "Текущая дата и время: " & _Now())
EndFunc
Такой пример есть в справке к функций _TimeToTicks.
А вот более продвинуты пример:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
;
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $iTimer, $sTDelim = _DateTimeGetDelim()
$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Time Script", 220, 90, -1, -1, BitOR (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$Time_Label = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)("Текущее время: " & _DateTimeGetCurrentTime($sTDelim), 40, 60)
$iTimer = _Timer_SetTimer($hGUI, 1000, "_Set_SystemTime_Proc")
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_SHOW), $hGUI)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
_Timer_KillTimer($hGUI, $iTimer)
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Set_SystemTime_Proc($hWnd, $nMsg, $lParam, $wParam)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($Time_Label, "Текущее время: " & _DateTimeGetCurrentTime($sTDelim))
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _DateTimeGetCurrentTime($sTDelim=":")
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) @HOUR (http://www.autoitscript.com/autoit3/docs/macros.htm#@HOUR) & $sTDelim & @MIN (http://www.autoitscript.com/autoit3/docs/macros.htm#@MIN) & $sTDelim & @SEC (http://www.autoitscript.com/autoit3/docs/macros.htm#@SEC)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _DateTimeGetDelim($sNowTime="")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $sRetDelim = RegRead (http://www.autoitscript.com/autoit3/docs/functions/RegRead.htm)("HKEY_CURRENT_USER\Control Panel\International", "sTime")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sRetDelim = "" And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) $sNowTime <> "" Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sRetDelim = StringLeft (http://www.autoitscript.com/autoit3/docs/functions/StringLeft.htm)(StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sNowTime, "[0-9]", ""), 1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sRetDelim = "" Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sRetDelim = ":"
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $sRetDelim
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
P.S
А как оно связано с авто опросом элементов GUI?
IronOleg
10-11-2009, 13:05
P.S
А как оно связано с авто опросом элементов GUI? »
Я думал что есть что то типа такой функции
Func _Set_SystemTime_Proc($hWnd, $nMsg, $lParam, $wParam)
GUICtrlSetData($Time_Label, "Текущее время: " & _DateTimeGetCurrentTime($sTDelim))
EndFunc »
А зачем нужны аргументы $hWnd, $nMsg, $lParam, $wParam, если в теле функции они не используются?
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC