May 7, 201016 yr I have a mystery problem with a Windows timer.I used to have a code like this: timerId = SetTimer(GetFSWindow(), 0, 200, (TIMERPROC)TimerTick); where GetFSWindow() returns the window handle of the FS window "FS98MAIN".This code used to work fine, and I changed other parts of the code. Then it appeared that the timer didn't work any more, the TImerTick function was not called any more. I tried to understand why, but I couldn't...So I changed the code into this: timerId = SetTimer(0, 0, 200, (TIMERPROC)TimerTick); The code now works fine again, my TimerTick function is called every 200 milliseconds. But I still wonder why a code that was working stopped working, and why changing the window handle by 0 could make it work again.If someone can help me understanding...Thanks,Eric My Web Site
May 8, 201016 yr Moderator Possibly because the parameter list has been expanded from 3 to 4? UINT_PTR SetTimer( HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc); Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
May 8, 201016 yr Commercial Member Description of the first parameter:"Handle to the window to be associated with the timer. This window must be owned by the calling thread. If a NULL value for hWnd is passed in along with an nIDEvent of an existing timer, that timer will be replaced in the same way that an existing non-NULL hWnd timer will be."Since you don't actually 'own' the FS window... you probably shouldn't be passing that window handle to the SetTimer function. Your timer needs to run 'independently', thus a NULL (0) value is best.When you define a 'SetTimer', a window can get a WM_TIMER message telling it to handle the timer. This could be one of the reasons why it's no longer working for you. Ed Wilson Mindstar AviationMy Playland - I69
May 8, 201016 yr Author Description of the first parameter:"Handle to the window to be associated with the timer. This window must be owned by the calling thread. If a NULL value for hWnd is passed in along with an nIDEvent of an existing timer, that timer will be replaced in the same way that an existing non-NULL hWnd timer will be."Since you don't actually 'own' the FS window... you probably shouldn't be passing that window handle to the SetTimer function. Your timer needs to run 'independently', thus a NULL (0) value is best.When you define a 'SetTimer', a window can get a WM_TIMER message telling it to handle the timer. This could be one of the reasons why it's no longer working for you.Yes, I think you're right. Maybe FS defines another timer with the same id as mine, so FS in fact replaces my timer.I still don't know why it was working before...I don't use the WM_TIMER message because I don't have a window (it is in a gauge), I just do what needs to be done in the timer proc that is called by the timer. At this time, everything seems to work fine.Thanks for your help !!Eric My Web Site
Create an account or sign in to comment