Click to See Complete Forum and Search --> : Set / KillTimer


C.Schlue
January 15th, 2004, 08:55 AM
Hi There.

In my App i use the SetTimer Function to register a WM_TIMER message.
According to msdn, SetTimer() returns a TimerID, which can be used to kill the timer ( KillTimer(tID) )

in my case SetTimer returns 0x1, The Timer works fine, but can't be killed :cry:

Marc G
January 15th, 2004, 10:13 AM
Can you post your code where you create and kill your timer?

C.Schlue
January 15th, 2004, 10:19 AM
Nothing special at all:

///////////////////////////////////////
.h

...
UINT m_tId;
...

///////////////////////////////////////
.cpp

...
m_tId = ::SetTimer(m_hWnd, 0, _ttoi(str), NULL);
...
::KillTimer(m_hWnd, m_tId);
...

///////////////////////////////////////
Just the usual way to set && kill timers... I guess

TSmooth
January 16th, 2004, 06:35 AM
From MSDN:


If the function succeeds and the hWnd parameter is not NULL, then the return value is a nonzero integer. An application can pass the value of the nIDEvent parameter to the KillTimer function to destroy the timer.


This is your case as you are passing it the hWnd parameter. Therefore, the 2nd paramter is the id assigned to the timer:

nIDEvent
[in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.


Thus, in your sample code, the id of the timer is 0 and you would kill it using this id. The return value is only of importance if it is 0 which means it failed in this case. I am, however, not sure if 0 is an allowed timer id but in any case, when you set the hwnd parameter, it is up to you to pick the timer id, one is not generated for you.