Jump to content

Setting Different Delay to GUIRegisterMsg


senatin
 Share

Go to solution Solved by Nine,

Recommended Posts

While Searching For my main problem I bumb into a reply That was so useful about Changing the time GUIRegisterMsg($WM_TIMER) is Triggered.
Unfortunately I Lost The File and I couldn't Recall and can't Find The Topic wherein because it has been long time.
the Script was, As I recall, Like This
 

GUIRegisterMsg($WM_TIMER, "PlayAnim")

Set$WM_Timer(3000)
Sleep(9000)
Set$WM_Timer(1000)
Sleep(9000)

Function PlayAnim()
{
    consolewrite("TickTimer")
}

The result:
it write TickTimer every 3sec within 9 seconds
after 9 seconds the console will write every 1 sec.

Edited by senatin
Link to comment
Share on other sites

  • Solution

You could use AdlibRegister function.  It would make your life easier. 

You can also use _Timer UDF.

But if you insist, you could use this :

#include <GUIConstants.au3>
#include <Constants.au3>
#include <WinAPISysWin.au3>

Global Const $nID = 50

Global $hGUI = GUICreate("Timer")
GUISetState()
GUIRegisterMsg($WM_TIMER, WM_TIMER)

Global $hTimer = _WinAPI_SetTimer($hGUI, $nID, 3000, 0)
If Not $hTimer Then Exit MsgBox($MB_SYSTEMMODAL, "", "Failed")
Sleep(9000)
Global $hTimer = _WinAPI_SetTimer($hGUI, $nID, 1000, 0)
If Not $hTimer Then Exit MsgBox($MB_SYSTEMMODAL, "", "Failed")

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_WinAPI_KillTimer($hGUI, $nID)

Func WM_TIMER($hWndGUI, $MsgID, $WParam, $LParam)
  ConsoleWrite("hWndGUI: " & $hWndGUI & " MsgID: " & $MsgID & " wParam: " & $WParam & " lParam: " & $LParam & @CRLF)
EndFunc   ;==>WM_TIMER

 

Link to comment
Share on other sites

@senatin

#include <Misc.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
GUIRegisterMsg($WM_TIMER, "PlayAnim")
Opt('TrayAutoPause', 0)
Local $hTimer = DllCallbackRegister('PlayAnim', 'none', 'hwnd;uint;uint_ptr;dword')
Global $pre_timer, $_state = Number("1"), $_state_1 = Number("1"), $timer_id
Do
    SetWM_Timer(3000)
    Sleep(9000)
    SetWM_Timer(1000)
    Sleep(9000)
Until _IsPressed('1B')
Func PlayAnim($hWnd, $iMsg, $iTimerID, $iTime)
    #forceref $hWnd, $iMsg, $iTimerID, $iTime
    consolewrite("TickTime" & @CRLF)
EndFunc   ;==>PlayAnim
Func SetWM_Timer($timer)
    if $_state = Number("1") Then
        if $_state_1 = Number("1") Then
            _WinAPI_KillTimer(0, $timer_id)
            DllCallbackFree($hTimer)
            Local $hTimer = DllCallbackRegister('PlayAnim', 'none', 'hwnd;uint;uint_ptr;dword')
            $timer_id = _WinAPI_SetTimer(0, 0, $timer, DllCallbackGetPtr($hTimer))
        EndIf
        $pre_timer = $timer
        $_state_1 = Number("0")
        $_state = Number("0")

    EndIf
    if $timer <> $pre_timer Then
        _WinAPI_KillTimer(0, $timer_id)
        DllCallbackFree($hTimer)
        Local $hTimer = DllCallbackRegister('PlayAnim', 'none', 'hwnd;uint;uint_ptr;dword')
        $timer_id = _WinAPI_SetTimer(0, 0, $timer, DllCallbackGetPtr($hTimer))
        $_state = Number("1")
        $_state_1 = Number("1")
    EndIf
EndFunc   ;==>SetWM_Timer

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...