Timer and GDI+ Window Update

R

Rohit

I have a timer object that calls UpdateWindow(). The WM_TIMER message is
processed in the main Win32 message loop for the window. However, when I run
the app, the image doesn't get updated (there is some animation that's
supposed to happen). However, if I constantly resize the window, the
animation happens as expected (but I want the animation to happen without me
having to mess with the window size). I verified that the timer is firing
correctly. What is the problem?
 
M

Mark Salsbery [MVP]

Rohit said:
I have a timer object that calls UpdateWindow(). The WM_TIMER message is
processed in the main Win32 message loop for the window. However, when I
run
the app, the image doesn't get updated (there is some animation that's
supposed to happen). However, if I constantly resize the window, the
animation happens as expected (but I want the animation to happen without
me
having to mess with the window size). I verified that the timer is firing
correctly. What is the problem?

Before updating the window, you also need to invalidate all or a portion of
the window.

See InvalidateRect(), etc.

Mark
 
R

Rohit

Thanks. That worked.

Now the problem is that there is too much flickering. Is there a way to
avoid that, or do I have to recode it in DirectX?
 
M

Mark Salsbery [MVP]

Rohit said:
Thanks. That worked.

Now the problem is that there is too much flickering. Is there a way to
avoid that, or do I have to recode it in DirectX?


You could invalidate only regions of the window that need redrawing...that
will reduce flicker.

Using a transparent background and doing all foreground drawing helps a lot.

You could use an offscreen buffer (double-buffering) to draw to and blt the
entire buffer to the screen when necessary.

DirectX is certainly a solution, but a different approach than GDI.

I personally do a lot of multimedia rendering, and find double buffering
works great for me, both with GDI/GDI+ and WPF.

Mark
 
R

Rohit

Can you describe how to use double-buffering to draw the scene to an off
screen buffer and blt the entire thing in GDI+? Or could you point me to
some example code on the Internet?

In Outlook 2003, when a new email arrives, the notification fades in and
out. This is most likely implemented using GDI+ and altering the
transparency factor. But there is not flicker. Do they use double-buffering
in this case?
 
R

Rohit

I found some code which draws the scene to a bitmap and then displays the
bitmap. However, the API calls did not take the device context as an
argument; consequently, nothing displayed in the window. Do you know how to
actually make the bitmap show up in the window?

BTW, I am programming in straight Win32 because I hate MFC and .NET.
 
R

Rohit

I figured it out. No more flickering - yay.

Rohit said:
I found some code which draws the scene to a bitmap and then displays the
bitmap. However, the API calls did not take the device context as an
argument; consequently, nothing displayed in the window. Do you know how to
actually make the bitmap show up in the window?

BTW, I am programming in straight Win32 because I hate MFC and .NET.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top