Opened on Nov 30, 2022 at 11:26:29 AM
Closed on Dec 1, 2022 at 5:23:31 PM
Last modified on Dec 2, 2022 at 6:29:16 PM
#3934 closed Feature Request (Completed)
_WinAPI_SetTimer TimerID must be nonzero
| Reported by: | KaFu | Owned by: | J-Paul Mesnage |
|---|---|---|---|
| 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.
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 by , on Nov 30, 2022 at 12:00:01 PM
| Version: | 3.3.16.1 |
|---|
comment:2 by , on Dec 1, 2022 at 2:41:41 PM
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 by , on Dec 1, 2022 at 5:23:31 PM
| Milestone: | → 3.3.17.0 |
|---|---|
| Owner: | set to |
| Resolution: | → Completed |
| Status: | new → closed |
Added by revision [12932] in version: 3.3.17.0
comment:4 by , on Dec 2, 2022 at 10:08:36 AM
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 by , on Dec 2, 2022 at 6:29:16 PM
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.

Automatic ticket cleanup.