Sign in to follow this  
Aprosenf

[Win32] How to do simple animation with GDI?

Recommended Posts

I'm looking for a way to do simple animation using Windows GDI in straight Win32. Basically all I want to do is play a short animation once when something happens, e.g. a button is hit or the user does something. Currently my main message loop uses GetMessage(). Would I want to do something like, if anything is currently animating, call PeekMessage(), sleep a few dozen milliseconds, and update the animation, otherwise call GetMessage()? I don't want to call PeekMessage() the whole time, since that would waste a horrendous amount of CPU time.

Share this post


Link to post
Share on other sites
Or use something like that: {still using PeekMessage()}


if PeekMessage(Msg, 0, 0, 0, PM_REMOVE)
{
if (Msg.Message != WM_QUIT)
{
TranslateMessage(Msg);
DispatchMessage(Msg);
}
else
{
terminate();
}
}
else
{
IdleProc();
}

...

void IdleProc(void)
{
//Place code to update animation
}






This will give you smooth results and update the animation only when the CPU has nothing to do. Using timers is also a good solution to your problem but the code to be executed in a WM_TIMER message will be executed even if the CPU has something else to do. That could make your system slower to other applications running.

Share this post


Link to post
Share on other sites
WM_TIMER is a good way to go but keep in mind that its a low priority message, meaning if there are other messages in the message que then the WM_TIMER will get bumped so your messages won't be delivered at exactly the same interval in which you specify.

Cheers
Chris

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this