Modify

Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#3934 closed Feature Request (Completed)

_WinAPI_SetTimer TimerID must be nonzero

Reported by: KaFu Owned by: Jpm
Milestone: 3.3.17.0 Component: Documentation
Version: Severity: None
Keywords: Cc:

Description

"A nonzero timer identifier" should be added to the TimerID description in _WinAPI_SetTimer().

Otherwise if set to 0, the return value of the function is not the TimerID.

See also:
https://www.autoitscript.com/forum/topic/209219-centered-fileopendialog-using-self-terminating-wm_timer-call/?do=findComment&comment=1509811

Maybe add a second example for this scenario without a callback function.

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

Opt('TrayAutoPause', 0)

Global $g_iCount = 0
Local $iTimerID = 999

Local $hGUI = GUICreate("Example")
GUIRegisterMsg($WM_TIMER, "WM_TIMER")

$iTimerID = _WinAPI_SetTimer($hGUI, $iTimerID, 1000, 0)

Do
    Sleep(100)
Until _IsPressed('1B')

_WinAPI_KillTimer($hGUI, $iTimerID)


Func WM_TIMER($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam

    ConsoleWrite($g_iCount & @CRLF)
    $g_iCount += 1

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_TIMER

Attachments (0)

Change History (5)

comment:1 Changed 17 months ago by TicketCleanup

  • Version 3.3.16.1 deleted

Automatic ticket cleanup.

comment:2 Changed 17 months ago by Jpm

I think that

Otherwise if set to 0, the return value of the function is not the TimerID


Is wrong as your example is demonstrating that the

_WinAPI_KillTimer($hGUI, $iTimerID)

is working

any way adding an example with last parameter set to 0 is a good idea

comment:3 Changed 17 months ago by Jpm

  • Milestone set to 3.3.17.0
  • Owner set to Jpm
  • Resolution set to Completed
  • Status changed from new to closed

Added by revision [12932] in version: 3.3.17.0

comment:4 Changed 17 months ago by KaFu

If you set the TimerID to 0, the return value is a 1 for success, and not the correct 0 for TimerID.

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Opt('TrayAutoPause', 0)

Local $hGUI = GUICreate("Example")

$hProc = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$hHook = _WinAPI_SetWindowLong($hGUI, $GWL_WNDPROC, DllCallbackGetPtr($hProc))

GUIRegisterMsg($WM_TIMER, "WM_TIMER")

; First Timer
$iTimerID_1 = _WinAPI_SetTimer($hGUI, 0, 1000, 0)
ConsoleWrite("$iTimerID= " & $iTimerID_1 & @CRLF)

; Second Timer
$iTimerID_2 = _WinAPI_SetTimer($hGUI, 999, 1000, 0)
ConsoleWrite("$iTimerID= " & $iTimerID_2 & @CRLF & @CRLF)

Do
	Sleep(100)
Until _IsPressed('1B')

ConsoleWrite("_WinAPI_KillTimer= " & _WinAPI_KillTimer($hGUI, $iTimerID_1) & @CRLF)     ; first timer returned 1 as TimerID, which is not correct
ConsoleWrite("_WinAPI_KillTimer= " & _WinAPI_KillTimer($hGUI, 0) & @CRLF)                 ; 0, as manually set for first timer, kills it
ConsoleWrite("_WinAPI_KillTimer= " & _WinAPI_KillTimer($hGUI, $iTimerID_2) & @CRLF)

_WinAPI_SetWindowLong($hGUI, $GWL_WNDPROC, $hHook)
DllCallbackFree($hProc)

Func WM_TIMER($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg, $iwParam, $ilParam
	ConsoleWrite("WM_TIMER= " & $hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @CRLF & @CRLF)
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_TIMER

Func _WinProc($hWnd, $iMsg, $iwParam, $ilParam)                                    ; == die Prozedur soll ausschließlich WM_NOTIFY auswerten
	If $iMsg = $WM_TIMER Then
		ConsoleWrite("_WinProc= " & $hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @CRLF)
	EndIf
	Return _WinAPI_CallWindowProc($hHook, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc   ;==>_WinProc

comment:5 Changed 17 months ago by pixelsearch

In case it may help you, there are 2 additional sentences found on msdn, topic KillTimer function (these 2 sentences are not found in AutoIt help file)

KillTimer function (winuser.h)

BOOL KillTimer(

[in, optional] HWND hWnd,
[in] UINT_PTR uIDEvent

);

...

[in] uIDEvent
Type: UINT_PTR

The timer to be destroyed.
If the window handle passed to SetTimer is valid, this parameter must be the same as the nIDEvent value passed to SetTimer.
If the application calls SetTimer with hWnd set to NULL, this parameter must be the timer identifier returned by SetTimer.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.