473,837 Members | 1,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7228
"Arnold the Aardvark" <no@way.com> wrote in message
news:c1******** ***********@new s.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
2223
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 make the polygon move but the screen flickers because I call invalidate() on the mouse down event. I did do offscreen buffering but there is still flashing in the screen. Let me explain what I am doing. in the pain even handler of the control I...
11
6209
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 OnPaint . The recangle draws correct when i press the mouse, but when i release the mouse the background is not restored What should i do in the Onpaint to make sure the background (the form) is restored correctly ? This problem already keeps...
8
3200
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 when the control is painted or resized. When the control is drawn it draws also the items found in the collection. So far so good.... I have 3 questions which I'm unable to find a solution
8
10823
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: Private Sub Draw() m_pPictBox.Refresh() ' Draw etc... End Sub Private Sub m_pTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_pTimer.Tick Draw()
6
3643
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 my main form in my VB.NET application. It does work and render correctly but the problem is that there is an awful flickering that happens on most PCs I try it on. The flickering is reminiscent of the sort that you get on a TV when it is not tuned...
1
3127
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 trying to also draw a background image. I have a form on which I have placed a panel. I am drawing on this panel little boxes as in the example but I also need to show a background image for the panel.
0
1225
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 middle of the form. The problem I am having is when I pass another window in front of it or drag the window, it doesn’t repaint with the transparent background. It just shows the drag marks of the window that I dragged in front of it. The other...
2
3343
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 screen and sometimes, i get a frame or two of just blank jframe color public void draw() { BufferStrategy bf = this.getBufferStrategy(); Graphics2D g = null; if(scrollPos>lastCoveredPos) lastCoveredPos =...
1
5141
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 following code. in the following code i am using SelectionArea class which extends a canvas on which i am performing drawing operation. i am using image variable in this class for double buffering to reduce flickering and to save the applet's previous...
0
9842
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10874
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10566
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10623
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9398
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5668
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3124
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.