PDA

View Full Version : OnIdle() implementation with Win32 API



yang22
08-19-2002, 11:03 AM
Last time, I asked the two thread programming problem-- the main thread is used to show the position of a manipulator; the other thread is used to control force output.

As someone pointed out, Calling RenderScene() in WM_TIMER makes the performance very bad. It's better to call RenderScene() during the idle time. How to implement the similiar functionality of OnIdle() under Win32 API platform? Thank you.

Deiussum
08-19-2002, 11:19 AM
By doing something like so for your message loop:






// Endless loop that you break out of on WM_QUIT
while(true)
{
// If a message comes in process it
if (PeekMessage())
{
if (msg == WM_QUIT)
break;
TranslateMessage();
DispatchMessage();
}

// Do your idle processing
OnIdle();
}



Obviously, you have to fill in the appropriate parameters for PeekMessage, TranslateMessage, and DispatchMessage, but that should give you a general idea.

yang22
08-19-2002, 11:38 AM
Thank you very much.
(1)My understanding is that this piece of code should be in the WinMain() function to process the message loop, is my understanding right?
i.e. use this piece of code to replace the normal message loop
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
right?

(2)I need to write my implementation of OnIdle(), i.e to call the RenderScene() and something like it. right?



Originally posted by Deiussum:
By doing something like so for your message loop:






// Endless loop that you break out of on WM_QUIT
while(true)
{
// If a message comes in process it
if (PeekMessage())
{
if (msg == WM_QUIT)
break;
TranslateMessage();
DispatchMessage();
}

// Do your idle processing
OnIdle();
}



Obviously, you have to fill in the appropriate parameters for PeekMessage, TranslateMessage, and DispatchMessage, but that should give you a general idea.