Connecting Tech Pros Worldwide Forums | Help | Site Map

Timer and GDI+ Window Update

=?Utf-8?B?Um9oaXQ=?=
Guest
 
Posts: n/a
#1: Jul 30 '08
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?

Mark Salsbery [MVP]
Guest
 
Posts: n/a
#2: Jul 30 '08

re: Timer and GDI+ Window Update


"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:7F8392D8-7DCA-44BA-9055-0C6FF44701C3@microsoft.com...
Quote:
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

--
Mark Salsbery
Microsoft MVP - Visual C++

=?Utf-8?B?Um9oaXQ=?=
Guest
 
Posts: n/a
#3: Aug 1 '08

re: Timer and GDI+ Window Update


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?

"Mark Salsbery [MVP]" wrote:
Quote:
"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:7F8392D8-7DCA-44BA-9055-0C6FF44701C3@microsoft.com...
Quote:
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
>
--
Mark Salsbery
Microsoft MVP - Visual C++
>
>
Mark Salsbery [MVP]
Guest
 
Posts: n/a
#4: Aug 1 '08

re: Timer and GDI+ Window Update


"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:64BF9304-CF68-4C21-AE2D-7C7AD9BADD73@microsoft.com...
Quote:
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

--
Mark Salsbery
Microsoft MVP - Visual C++

Quote:
>
"Mark Salsbery [MVP]" wrote:
>
Quote:
>"Rohit" <Rohit@discussions.microsoft.comwrote in message
>news:7F8392D8-7DCA-44BA-9055-0C6FF44701C3@microsoft.com...
Quote:
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
>>
>--
>Mark Salsbery
>Microsoft MVP - Visual C++
>>
>>
=?Utf-8?B?Um9oaXQ=?=
Guest
 
Posts: n/a
#5: Aug 2 '08

re: Timer and GDI+ Window Update


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?

"Mark Salsbery [MVP]" wrote:
Quote:
"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:64BF9304-CF68-4C21-AE2D-7C7AD9BADD73@microsoft.com...
Quote:
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
>
--
Mark Salsbery
Microsoft MVP - Visual C++
>
>
Quote:

"Mark Salsbery [MVP]" wrote:
Quote:
"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:7F8392D8-7DCA-44BA-9055-0C6FF44701C3@microsoft.com...
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
>
--
Mark Salsbery
Microsoft MVP - Visual C++
>
>
>
=?Utf-8?B?Um9oaXQ=?=
Guest
 
Posts: n/a
#6: Aug 2 '08

re: Timer and GDI+ Window Update


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.

"Rohit" wrote:
Quote:
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?
>
"Mark Salsbery [MVP]" wrote:
>
Quote:
"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:64BF9304-CF68-4C21-AE2D-7C7AD9BADD73@microsoft.com...
Quote:
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

--
Mark Salsbery
Microsoft MVP - Visual C++

Quote:
>
"Mark Salsbery [MVP]" wrote:
>
>"Rohit" <Rohit@discussions.microsoft.comwrote in message
>news:7F8392D8-7DCA-44BA-9055-0C6FF44701C3@microsoft.com...
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
>>
>--
>Mark Salsbery
>Microsoft MVP - Visual C++
>>
>>
=?Utf-8?B?Um9oaXQ=?=
Guest
 
Posts: n/a
#7: Aug 2 '08

re: Timer and GDI+ Window Update


I figured it out. No more flickering - yay.

"Rohit" wrote:
Quote:
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.
>
"Rohit" wrote:
>
Quote:
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?

"Mark Salsbery [MVP]" wrote:
Quote:
"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:64BF9304-CF68-4C21-AE2D-7C7AD9BADD73@microsoft.com...
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
>
--
Mark Salsbery
Microsoft MVP - Visual C++
>
>

"Mark Salsbery [MVP]" wrote:

"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:7F8392D8-7DCA-44BA-9055-0C6FF44701C3@microsoft.com...
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
>
--
Mark Salsbery
Microsoft MVP - Visual C++
>
>
>
Mark Salsbery [MVP]
Guest
 
Posts: n/a
#8: Aug 2 '08

re: Timer and GDI+ Window Update


"Rohit" <Rohit@discussions.microsoft.comwrote in message
news:0E81E538-B639-4EDB-BCD1-B32B1356D62B@microsoft.com...
Quote:
I figured it out. No more flickering - yay.

Cool :-)

Cheers,
Mark

--
Mark Salsbery
Microsoft MVP - Visual C++





Closed Thread