what do you think of my message loop for DirectX proj
-
MSG msg; while( TRUE ) { if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT ) { break; } TranslateMessage( &msg ); DispatchMessage( &msg ); } }
IM PROUD TO BE A GMAIL;Yes, it's a message loop and ...??? What is EXACTLY the question ?
-
Yes, it's a message loop and ...??? What is EXACTLY the question ?
-
MSG msg; while( TRUE ) { if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT ) { break; } TranslateMessage( &msg ); DispatchMessage( &msg ); } }
IM PROUD TO BE A GMAIL;Because you're using
PeekMessage
rather thenGetMessage
your loop spins in the outerwhile
loop even when there is no message to process. Unless you have anelse
not show in the code above in theif ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
statement this code is needlessly inefficient. I would suggest you replace it with aGetMessage
and watch the CPU usage go down. Steve -
Because you're using
PeekMessage
rather thenGetMessage
your loop spins in the outerwhile
loop even when there is no message to process. Unless you have anelse
not show in the code above in theif ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
statement this code is needlessly inefficient. I would suggest you replace it with aGetMessage
and watch the CPU usage go down. Steve -
thank you for the comment, and yes I do have an else statement in the block but forgot to write it in. so you think it will still be good if it has an else block or should i stick with getmessage? IM PROUD TO BE A GMAIL;
Normally you'd use
PeekMessage
and perform some idle time processing in theelse
part. I'm not sure what's going on in theelse
bit but it looks ok to me. I find myself a little concerned that you may be busy waiting but I'd have to see theelse
bit to be sure. Steve