Reputation: 119
After created the window, i started a timer to do sth. the code like this:
SetTimer(hWnd, 1, 40, NULL); //tick each 40 ms.
I traced the last error, which was 0. but i cannot receive wm_timer! code like this:
case WM_TIMER:
{
//...
}
My IDE is VS2010, and OS is Windows7, so is there some speical case about my used environment?
P.S. okay i provide more code, it's a win32 app so in WinMain:
HWND hWnd = CreateWindow(...); //style : WS_POPUP | WS_VISIBLE , return is good
SetTimer(hWnd, 1, 40, NULL); //return is good too.
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
and the WndProc:
switch(message)
{
case WM_TIMER:
{
DebugBreak(); //no reaction
}
break;
.......
}
Upvotes: 2
Views: 1434
Reputation: 1
I have the same problem. If I put "SetTimer()
" in the WM_CREATE
section it does not start. However, if I create a menu option that I need to click on, and the put the "SetTimer()
" function in there,
it works.
case WM_CREATE:
{
SetTimer(hWnd, 1, 1000, NULL); // does not work here
return 0:
}
case ID_TIMER_START:
{
SetTimer(hWnd, 1, 1000, NULL); // works here
return 0;
}
Upvotes: 0
Reputation: 16582
WM_TIMER
won't fire if you're failing to consume other messages, as they will take priority. One cause of that, for example, is not correctly processing WM_PAINT
messages (you must BeginPaint()
/ EndPaint()
)
Upvotes: 2
Reputation: 535
To the best of my recollection, the problem stems from the fact you placed the SetTimer call too early. Place it in WM_CREATE.
switch(message)
{
case WM_CREATE:
{
SetTimer(hWnd, 1, 40, NULL);
}
case WM_TIMER:
{
DebugBreak(); //no reaction
}
break;
.......
}
I don't see any other reason why this should malfunction.
Upvotes: 1