SetTimer() and KillTimer()
-
I am having trouble killing my timer. It crashs everytime it is killed with an assertion that checks hWnd. The real problem is that the timerID passed to OnTimer is bad. SetTimer returns the correct timerId which I set to 255. OnTimer gets something like 6603033, and the number is always the same. If, inside OnTimer, I use KillTimer(6603033), it works. I suspect this number may change however....and I don't know where this # comes from? I am using CBitmapButtons and I noticed someone else has a similar problem on here. When they added a CBitmapButton, their OnTimer() fails to get called at all. Any suggestions? Thanks
-
I am having trouble killing my timer. It crashs everytime it is killed with an assertion that checks hWnd. The real problem is that the timerID passed to OnTimer is bad. SetTimer returns the correct timerId which I set to 255. OnTimer gets something like 6603033, and the number is always the same. If, inside OnTimer, I use KillTimer(6603033), it works. I suspect this number may change however....and I don't know where this # comes from? I am using CBitmapButtons and I noticed someone else has a similar problem on here. When they added a CBitmapButton, their OnTimer() fails to get called at all. Any suggestions? Thanks
Which value are you passing as the parameter to KillTimer()? The return value from SetTimer() or the nIDEvent parameter from the SetTimer() call ? The doc seems to imply the return value, but the argument list defintions seem to imply the nIDEvent. (see below) UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) ); BOOL KillTimer( int nIDEvent ); I have used the SetTimer(), KillTimer() a lot, and I have been passing the nIDEvent to KillTimer() ... Example : int timerResult = SetTimer(1,500,NULL); KillTimer(1);
-
I am having trouble killing my timer. It crashs everytime it is killed with an assertion that checks hWnd. The real problem is that the timerID passed to OnTimer is bad. SetTimer returns the correct timerId which I set to 255. OnTimer gets something like 6603033, and the number is always the same. If, inside OnTimer, I use KillTimer(6603033), it works. I suspect this number may change however....and I don't know where this # comes from? I am using CBitmapButtons and I noticed someone else has a similar problem on here. When they added a CBitmapButton, their OnTimer() fails to get called at all. Any suggestions? Thanks
Things to check: 1. Is the timerid you supply for SetTimer a variable? If yes, check your program to see it doesn't get changed somewhere. I typically "define" them For instance: #define TIMER_ID 1 #define TIMER_TIME 1000 #define TIMER_ID_DIS 2 #define TIMER_TIME_DIS 60000 Then in my OnTimer message i check for TIMER_ID & TIMER_ID_DIS 2. Are you forwarding the timer message to another window? That might (not sure) it to be different. 3.>> It crashs everytime it is killed with an assertion >>that checks hWnd. That might suggest that the window(CWnd, CButton, everthing derived from CWnd/CWindow) is already destroyed. If you are trying to kill your timer in the destructor of your window, don't!!! Destroy it in an OnClose or something but not in a destructor because the m_hWnd is already invalid then. In none of these is the case, show us the important parts of the code. Benedict Verheyen