Click here to Skip to main content
13,054,329 members (125,339 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

There are lot of drawings in my SDI application.when i scroll the window it flickers much.Can any one pls give me the easy way to handle the flickeing.I have created objects for each class(contains drawings such as rect,ellipse)in OnDraw.And my code to draw a PolyLine is as follows,

Calc_Line* objPline = new Calc_Line();
objPline->Place_Line(667-posX,155-posY,675-posX,155-posY,675-posX,185-posY,667-posX,185-posY);//Function Calling
//pDC in called function.

Here PosX,PosY are the positions of Scroll Point after scrolling,(Recalculating the points),Like this i have drawn all the drawings,Need ur assistance to stop flickering.

Thanking in advance,
Posted 2-Mar-10 2:40am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This usually happens because the background is first erased before the contents are redrawn.
This is not needed if you're doing all the erasing and drawing yourself.

So handle the WM_ERASEBKGND message and return a nonzero value.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

«_Superman_»'s answer gives you the basic principle. Erasing the background (painting it all white) then drawing on top of it is the easy, common, simple approach to handling the display. However, it is susceptible to flicker. On the same principle, drawing a solid rectangle on the display and then a different color, overlapping rectangle is also a source of flicker.

Now, how do you implement «_Superman_»'s advice and extend it to include dealing with drawing overlapping stuff? One approach to deal with this is called double buffering. If you search, you will find material about this both on CodeProject and the rest of the web. I would suggest this article[^].

Doing this is more important than my other response's suggestion of using ScrollWindow(). Once you do this, ScrollWindow() use is more a potential optimization than flicker reduction.

If your window contains child window controls, you might also want to look at the WS_CLIPCHILDREN windows style.
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

To illiminate flickering completelly you shoud trap de OnEraseBackground and don't call the based class and return FALSE... I think it is FALSE of maybe TRUE but you shouldnt call the base class...

After that you should use a Memory DC to draw...

This will elliminate flickering definitelly!!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Are you using CWnd::ScrollWindow to minimize the region you need to repaint?

Let me clarify: this is intended as a possible supplement to «_Superman_»'s answer. It may help, but will not resolve everything. It may also help speed up your repaints, if your OnDraw() code is smart enough to only repaint the invalid portion of the client area.

To use this, instead of calling CWnd::Invalidate in OnHScroll and OnVScroll, you would call CWnd::ScrollWindow or CWnd::ScrollWindowEx. This will scroll what is already displayed in the client area by the amount that you specify in its arguments. It will invalidate only that portion of the client area that was, so to speak, "uncovered". (Make sure you get the flags argument to ScrollWindowEx right.) This way you do not have to redraw the "moved" portion of your display. That portion should not flicker either. However, this will not help for the "uncovered" portion - just make it smaller.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 4 Mar 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100