Click here to Skip to main content
15,907,000 members
Please Sign up or sign in to vote.
4.00/5 (1 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,
Shiva..
Posted

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.
 
Share this answer
 
«_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.
 
Share this answer
 
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!!
 
Share this answer
 
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900