How to use MemDC when am painting a circle – to avoid flicker.-Collection of common programming errors
.png)
msdn Hi,I am using a SDI – Application. In the Views (OnPaint()) am painting a portion of circle with different colours (RGB values calculated on runtime).Initially had flicker efect for the entire view. I avoided it by making the circle as a region and invalidating only the region part.Let me know how to use MemDC to do this?
-
7 Answers
.png)
msdn1 You should copy your memory DC into the paint area where the circle is going to be drawn. But even if you did it otherwise, the controls would not be affected, if you have the WS_CLIPCHILDREN style (default style) in your window..png)
msdn2 Hi,Thanks.Will verify this and get back.Regards.
.png)
msdn3 Handle OnEraseBkgd() inside your code. Thanks.png)
msdn4I have to disagree with you on this Pintu. If you don’t use “double buffering”, i.e., if you don’t paint to a memory DC and than BitBlt() to the screen DC, there’ll be some flicker, even if you process the WM_ERASEBKGND message.
.png)
msdn5 The WM_ERASEBKGND trick works on fast computers. An old IT saying is “Computers make very fast, very accurate mistakes”, in this case I would say “Fast computers deliver fast mistakes”. “Locking” the application in the ERASEBKGND works for small areas.When I need better fixed graphics, I use a third buffer. This way any ERASE/PAINT will never affect the interface output because my thread(s) designing is not done …CopyBufferDC = InterlockedCompareExchange( is thread running ) == 1 ? BackBufferDC : ThreadBufferDCBitBlt( FrontBufferDC, CopyBufferDC) …
.png)
msdn6 Hi,In my view i have a paint area for circle and next to it are some controls like edit boxes, buttons etc. Can I copy to my memdc only the paint area (i mean where am drawing circle) and then copy back to the same coordinates (also considering the resize of view into consideration).Thanks for all your responses.If yes. How?Regards.
.png)
msdn7 You should copy your memory DC into the paint area where the circle is going to be drawn. But even if you did it otherwise, the controls would not be affected, if you have the WS_CLIPCHILDREN style (default style) in your window.