Jump to content
  • Advertisement
Sign in to follow this  
Legion55

problem with the Message loop in C++

This topic is 3712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!