473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem with custom draw flickering in MFC

[New to MFC]

I am creating a custom draw tree view based on CTreeCtrl.
When the control is re-sized the background is blanked
completely, resulting in a horrible flicker.

I've seen various suggestions involving the use of double
buffering. Those are fine but I want to understand what is
wrong. When I created the same control in C++Builder the
view was totally flicker free, so this must be something
the framework does (or doesn't).

Now, from the good old days of plain C API programming, I
vaguely remember that you could override the default
behaviour of a window class (to blank the background with
the brush supplied in WNDCLASS). Gonna have to find my
Petzold... :-)

So my question is: how do I do this in MFC? I have spent
all afternoon fiddling with likely candidates, but the
tree view is blanked before any of them are called.

Also, how can a tell Windows to start sending all the
Custom Draw notifications from inside OnPaint()?

Thanks.
Arnold the Aardvark

'And no, C++ does not have "garbage collection".
Thank God for that. C++ gives me the ability to not
create garbage in the first place.' - Ed Mulroy
Nov 17 '05 #1
3 7188
"Arnold the Aardvark" <no@way.com> wrote in message
news:c1*******************@news.demon.co.uk...
[New to MFC]

I am creating a custom draw tree view based on CTreeCtrl.
When the control is re-sized the background is blanked
completely, resulting in a horrible flicker.

I've seen various suggestions involving the use of double
buffering. Those are fine but I want to understand what is
wrong. When I created the same control in C++Builder the
view was totally flicker free, so this must be something
the framework does (or doesn't).
Perhaps c++ builder does double buffering by default (ie the DC you get is a
memory DC that is later put to screen).
Now, from the good old days of plain C API programming, I
vaguely remember that you could override the default
behaviour of a window class (to blank the background with
the brush supplied in WNDCLASS). Gonna have to find my
Petzold... :-)

So my question is: how do I do this in MFC? I have spent
all afternoon fiddling with likely candidates, but the
tree view is blanked before any of them are called.

Also, how can a tell Windows to start sending all the
Custom Draw notifications from inside OnPaint()?

Thanks.
Arnold the Aardvark

'And no, C++ does not have "garbage collection".
Thank God for that. C++ gives me the ability to not
create garbage in the first place.' - Ed Mulroy


Lol. Wouldn't memory leaks classify under 'garbage'? ;-) They pollute don't
they? Lol

http://www.codeproject.com/gdi/flickerfree.asp
http://www.codeproject.com/gdi/flicker_free_intro.asp

---
Cheers,
Tom Tempelaere
Nov 17 '05 #2
Make sure that you: get the proper DC to draw on (should be clipped to just the
invalidated area), select a clipping region into the DC for the invalidated
area prior to drawing, or limit your drawing to just the invalidated region.

Also, there are windows flags that affect how sizing invalidations are handled
-- whether or not a size invalidates the entire client area, or just the
affected portion.

Arnold the Aardvark wrote:

[New to MFC]

I am creating a custom draw tree view based on CTreeCtrl.
When the control is re-sized the background is blanked
completely, resulting in a horrible flicker.

I've seen various suggestions involving the use of double
buffering. Those are fine but I want to understand what is
wrong. When I created the same control in C++Builder the
view was totally flicker free, so this must be something
the framework does (or doesn't).

Now, from the good old days of plain C API programming, I
vaguely remember that you could override the default
behaviour of a window class (to blank the background with
the brush supplied in WNDCLASS). Gonna have to find my
Petzold... :-)

So my question is: how do I do this in MFC? I have spent
all afternoon fiddling with likely candidates, but the
tree view is blanked before any of them are called.

Also, how can a tell Windows to start sending all the
Custom Draw notifications from inside OnPaint()?

Thanks.
Arnold the Aardvark

'And no, C++ does not have "garbage collection".
Thank God for that. C++ gives me the ability to not
create garbage in the first place.' - Ed Mulroy

Nov 17 '05 #3
TT (Tom Tempelaere) wrote:
"Arnold the Aardvark" <no@way.com> wrote
I am creating a custom draw tree view based on CTreeCtrl.
When the control is re-sized the background is blanked
completely, resulting in a horrible flicker.
I sorted this out - mostly. The problem was the interaction
with the CView holding my control. I had to override the
default OnEraseBkgnd. I think the CView class might not
clip children, so when it clears (despite none of it being
visible), it wipes the tree out completely.

There is still a bit of flicker due to my own painting, but
it is much better than before. I could probably live with it.
I might look into some of the other custom draw stages...
Perhaps c++ builder does double buffering by default (ie the
DC you get is a memory DC that is later put to screen).
I don't think so. However, the image in Builder is absolutely
rock solid - no detectable flicker whatsoever - so I'll have
to look a bit more deeply into what's going on. You may be
right though that seems awfully wasteful for a default
implementation.
'And no, C++ does not have "garbage collection".
Thank God for that. C++ gives me the ability to not
create garbage in the first place.' - Ed Mulroy

Lol. Wouldn't memory leaks classify under 'garbage'? ;-) They pollute
don't they? Lol
I think Ed's point was that it is not difficult to write C++ that
will not leak resources even in the presence of exceptions, thanks
to the RAII idiom. In any case, GC only protects memory and seems
to create more problems than solutions if you want determinisic
clean up of other resources, such as mutex locks. YMMV.
http://www.codeproject.com/gdi/flickerfree.asp
http://www.codeproject.com/gdi/flicker_free_intro.asp


Thanks for these links.
Arnold the Aardvark
http://www.codeproject.com/cpp/garbage_collect.asp

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Abhishek | last post by:
My objective is quite simple. I want to display a JPG image and then on it overlay a polygon. This polygon can be moved by a user. The even is trapped on the mouse down event of the control. I can...
11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
8
by: Ryan Chavez | last post by:
Hello, I'm working on a project that basically draws lines onto a PictureBox control. Now I'm using a Timer with an interval of 100 to draw the information. Now my code looks something like this:...
6
by: Mark Thompson | last post by:
I have a problem with my Visual Basic .NET 2003 application which I have so far been unable to resolve. I am trying to get an OpenGL control that I have created working properly as a control on...
1
by: jediknight | last post by:
Hi All, I am trying to use the example in codeproject (http://www.codeproject.com/cs/media/flickerFreeDrawing.asp) called Flicker free drawing using GDI+ and C# which all well and good but I am...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I have a borderless form that has a transparent background. I only wanted the color that I painted the background with to be transparent and not the controls on the form or the box I draw in the...
2
by: drsmooth | last post by:
Hi, i have made several different things using a double buffer and a jframe before but never had this problem: if you look thrugh the code, you can see that i draw a whole bunch of stuff to the...
1
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.