不关闭GUI情况下,每隔1秒或指定时间获取电脑本地时间后显示在GUI界面上【已解决】
本帖最后由 tu0129 于 2014-9-13 09:30 编辑大家好,我想要在不关闭GUI情况下,每隔1秒或指定时间获取电脑本地时间后显示在GUI界面上,不会写循环更新的代码,只能写出来下面这个固定的,请会的帮帮我,谢谢了!#Include <Date.au3>
#include <CommMG.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $iMemo,$sMessage
_one()
Func _one()
$Gui = GUICreate("test",-1,240,-1,-1,0x80000,1)
GUISetState(@SW_SHOW)
$iMemo = GUICtrlCreateEdit("",15,15,370,190)
$tCur = _Date_Time_GetLocalTime()
MemoWrite( _Date_Time_SystemTimeToDateTimeStr($tCur))
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
exit
EndSwitch
WEnd
GUIDelete($Gui)
EndFunc
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc
;请参考AutoIt帮助文件之GUIRegisterMsg 、_WinAPI_SetTimer 、_WinAPI_KillTimer 、
;_Date_Time_GetLocalTime、_Date_Time_SystemTimeToTimeStr
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <Date.au3>
#Include <WinAPIEx.au3>
Global $hEdit
Example()
Func Example()
Local Const $BS_OWNERDRAW = 0x0000000B
Local $hGUI, $GUIMsg
$hGUI = GUICreate("My Ownerdrawn Created Button", 300, 200)
$hEdit = GUICtrlCreateEdit("First line" & @CRLF, 10, 10, 200, 100, $ES_AUTOVSCROLL + $WS_VSCROLL)
GUIRegisterMsg($WM_TIMER, "MY_TIMERPROC")
GUISetState()
_WinAPI_SetTimer ($hGUI, 0, 1000, 0)
While 1
$GUIMsg = GUIGetMsg()
Switch $GUIMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_WinAPI_KillTimer($hGUI, 0)
EndFunc ;==>Example
Func MY_TIMERPROC($hWnd, $Msg, $wParam, $lParam)
$tNew = _Date_Time_EncodeSystemTime(8, 19, @YEAR, 3, 10, 45)
$tNew = _Date_Time_GetLocalTime()
$str = _Date_Time_SystemTimeToTimeStr($tNew)
GUICtrlSetData($hEdit, $str)
EndFunc
附上 WinAPIEx.au3
#Include <Date.au3>
#include <CommMG.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $iMemo,$sMessage
_one()
Func _one()
$Gui = GUICreate("test",-1,240,-1,-1,0x80000,1)
GUISetState(@SW_SHOW)
$iMemo = GUICtrlCreateEdit("",15,15,370,190)
While 1
$tCur = _Date_Time_GetLocalTime()
MemoWrite( _Date_Time_SystemTimeToDateTimeStr($tCur))
sleep (1000)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
exit
EndSwitch
WEnd
GUIDelete($Gui)
EndFunc
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc
把设置命令放到循环里就可以了 回复 2# veket_linux
谢谢! 回复 3# 骗子
这样就不能正常点击关闭按钮来关闭GUI了 2楼的代码有些复杂了,简单的修改了一下楼主的码~~#Include <Date.au3>
;#include <CommMG.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $iMemo,$sMessage
_one()
Func _one()
$Gui = GUICreate("test",-1,240,-1,-1,0x80000,1)
GUISetState(@SW_SHOW)
$iMemo = GUICtrlCreateEdit("",15,15,370,190)
$time = TimerInit()
While 1
If TimerDiff($time) > 1000 Then
$tCur = _Date_Time_GetLocalTime()
MemoWrite( _Date_Time_SystemTimeToDateTimeStr($tCur))
$time = TimerInit()
EndIf
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
exit
EndSwitch
WEnd
GUIDelete($Gui)
EndFunc
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc 回复 6# austere
感谢! 学习了。。。。
页:
[1]