problem with the Message loop in C++

Started by
3 comments, last by AtsusaKai 15 years, 9 months ago
hello everyone.. and thanks for read.... i have a problem with the window message loop function, ive initialized the directx sucessful and when i try to implement the render function it never happen, this is the code segment: /*...*/ int Run(void) { while(1) { if (PeekMessage( &kMessage, NULL, 0, 0, PM_REMOVE )) { if(WM_QUIT == kMessage.message) { break; } else { TranslateMessage (&kMessage); DispatchMessage (&kMessage); } } else { Render(); } } return(int) kMessage.wParam; } /*...*/ the window then appears but never changes the color to blue(Render must changes the color to blue) so I supoose there always the peekmessage is in 1 or true and the last "else" never is done...the question is why¡¡?? i hope you understand what i try to say. but if I put the render funtion in the wndproc the the window changes the color : /**/ LRESULT CALLBACK WndProc (HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { switch(iMessage) { case WM_CREATE: return(0); case WM_PAINT: Render(); return(0); case WM_DESTROY: PostQuitMessage(0); return(0); default: return DefWindowProc(hWnd, iMessage, wParam, lParam); } } /**/ please tellme whats wrong, i use the visual studio.net 2005 thanks
Advertisement
Im not sure how its done in DirectX but you need to swap the display buffers.

Render(); // user defined
Swapem(); // directx defined

Swapem() is not the real name of the function (just an example).
You need to find out what the real function is for DirectX.
Hope this helps...
You might get swamped with WM_PAINT messages. In WM_PAINT you should either use BeginPaint/EndPaint or use ValidateRect manually to tell Windows that the HWND has been repainted.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Try to use the debugger to see if your code ever gets inside the Render function. And if so, could you post the Render function?

Try removing the else clause on your PeekMessage statement, the Render() method wasn't probably able to execute. Just a suggestion...

[source language=cpp]void Run(){   while (TRUE)   {       // peek message statement       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))       {           if (msg.message == WM_QUIT)              break;           TranslateMessage(&msg);           DispatchMessage(&msg);       }       // else clause removed       // do the render       Render();   }   return (int)msg.wparam;}

This topic is closed to new replies.

Advertisement