initialize
MSG msg;
while(msg.message !=WM_QUIT)
{ ....
if msg is not been initalized? why runtime error arise??
I just do a compare operation.
if your msg is not been initialized there is also no data attached to your msg var. The compiler can't do the comparision and the run-time error arises.
(It would be easier for us if we know which error arises.)
(It would be easier for us if we know which error arises.)
If that's the entire example then the problem is that you've never actually set the message to anything (through GetMessage or PeekMessage for example).
The loop will likely have to be restructured such that the message retrieval function is called first. Try calling it within the while expression, switch to a do { .. } while() loop or an internal if condition that breaks out of it.
The loop will likely have to be restructured such that the message retrieval function is called first. Try calling it within the while expression, switch to a do { .. } while() loop or an internal if condition that breaks out of it.
Nah, you just need to put
So it should look like this:
EDIT: oops, commented out mushu-specific code [lol]
ZeroMemory(&msg, sizeof(MSG));
right after you declare msg, otherwise it'll just be filled with garbage.So it should look like this:
MSG msg; ZeroMemory(&msg, sizeof(MSG)); while (msg.message != WM_QUIT) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } //myDx->render(); }
EDIT: oops, commented out mushu-specific code [lol]
Quote:Original post by MushuI guess that works but you probably only replaced a gamble at runtime for one at compiletime.
Nah, you just need to putright after you declare msg, otherwise it'll just be filled with garbage.ZeroMemory(&msg, sizeof(MSG));
What if WM_QUIT happened to be defined as 0 (it's 18 by the way)? I suppose that the loop is unlikely to have any significant extra processing of WM_NULL but this kind of assumption still seems is a bit dangerous to me.
Besides replacing the loop with a 'do { } while' would simplify the code without affecting it's behaviour.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement