找回密码
 加入
搜索
查看: 7559|回复: 7

[GUI管理] 不关闭GUI情况下,每隔1秒或指定时间获取电脑本地时间后显示在GUI界面上【已解决】

  [复制链接]
发表于 2014-9-12 16:34:53 | 显示全部楼层 |阅读模式
本帖最后由 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   
发表于 2014-9-12 17:35:40 | 显示全部楼层

;请参考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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2014-9-13 06:08:22 | 显示全部楼层
#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   

把设置命令放到循环里就可以了
 楼主| 发表于 2014-9-13 08:05:26 | 显示全部楼层
回复 2# veket_linux


    谢谢!
 楼主| 发表于 2014-9-13 08:07:04 | 显示全部楼层
回复 3# 骗子


    这样就不能正常点击关闭按钮来关闭GUI了
发表于 2014-9-13 08:52:52 | 显示全部楼层
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   
 楼主| 发表于 2014-9-13 09:30:19 | 显示全部楼层
回复 6# austere


    感谢!
发表于 2016-1-10 11:42:36 | 显示全部楼层
学习了。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 15:39 , Processed in 0.100649 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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