Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetTimer() does not work

Status
Not open for further replies.

tchouch

Programmer
Apr 18, 2001
300
0
0
DE

I write a non-MFC Win32 application and try to use Timer to redraw some controls. But
callback function TimerProc is not called. I have often used timers before and all have
worked fine.
I start timer with the code

UINT g_Timer = 0; //global
void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD
dwTime)
{
....
}

void Dlg_OnCommand()
{
...
UINT TimerID = 1005; //local
while((g_Timer = SetTimer(g_hDlg, TimerID, 1000, (TIMERPROC)MyTimerProc )) ==
0)
TimerID++;
...
}

After this call g_Timer is the same as TimerID (1005, and it is right, i think). g_hDlg is
a valid window (Dialog in Dialog - based application, and I start the timer with a button
- g_hDlg is visible, another features are started fine with this button).

{
...
if(g_Timer)
KillTimer(g_hDlg, g_Timer);
...
}
works too, only MyTimerProc() is not called (in Debug and Release)...
Does anybody know a solution?
 
according to msdn :)
if u supply a hwnd (your case with the dialog's handler) when the timer timeout time elapses a WM_TIMER message will be sent to the window.
i think that timerproc is called ONLY if u dont supply a hwnd (i.e. leave the parameter as NULL), anyway u can check that:

1) define a WM_TIMER handler and see if u get the message :)
2) try to set the hwnd param to NULL and see if timerproc will get called

hope it helps
 
I have all that of course tried (NULL handles, desktop window, another TimerIDs, only message handler without TimerProc, set timer by dialog init or if I nead it only, two timers etc.). I have tried to use SetWindowsHookEx() too. The Problem is, the message WM_TIMER does not come if I work with internet Functions and use wait cursor (or app. starting cursor) for my application. Normally, the application has the message and works with it correctly. I think, the Problem is with Priority of WM_TIMER message.
 
I don't know much about timers, but your code above defines a function calle TimerProc and you try to call MyTimerProc. Is it the real problem here or is it only a past typo?

Vincent
 
i'd go for that as well. msdn says that wm_timer is a low priority msg and i guess it does not get sent. i did a simple test -- set up a timer and drag the window... no matter the timer expires if the window is dragged at that time tha msg does not get sent

you can go for some other type of timer, multimedia, high resolution, seems more exotic but it might work :))

the most brutal thing i can think of is to setup a separate timer thread that sends messages/signals events/calls methods at predefined intervals. sleep()?
but that's really killing bunnies with axes :)
 
Thanks,

i will try with another timers. I don't will to use system timer for that (int0) - the application should work on all Win32 systems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top