{"id":3965,"date":"2014-03-30T06:44:33","date_gmt":"2014-03-30T06:44:33","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-use-memdc-when-am-painting-a-circle-to-avoid-flicker-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:44:33","modified_gmt":"2014-03-30T06:44:33","slug":"how-to-use-memdc-when-am-painting-a-circle-to-avoid-flicker-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-use-memdc-when-am-painting-a-circle-to-avoid-flicker-collection-of-common-programming-errors\/","title":{"rendered":"How to use MemDC when am painting a circle &#8211; to avoid flicker.-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn Hi,I am using a SDI &#8211; Application.\u00a0In the Views\u00a0(OnPaint())\u00a0am 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.<\/p>\n<p>Let me know how to use MemDC to\u00a0do this?<\/p>\n<\/li>\n<li>\n<h3>7 Answers<\/h3>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn1 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)\u00a0in your window.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn2 Hi,Thanks.Will verify this and get back.<\/p>\n<p>Regards.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn3 Handle OnEraseBkgd() inside your code. Thanks<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn4<\/p>\n<p>I have to disagree with you on this Pintu. If you don&#8217;t use &#8220;double buffering&#8221;, i.e., if you don&#8217;t paint to a memory DC and than BitBlt() to the screen DC, there&#8217;ll be some flicker, even if you process the WM_ERASEBKGND message.\u00a0<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn5 The WM_ERASEBKGND trick works on fast computers. An old IT saying is\u00a0&#8220;Computers make very fast, very accurate mistakes&#8221;, in this case\u00a0I would say\u00a0&#8220;Fast computers deliver\u00a0fast mistakes&#8221;. &#8220;Locking&#8221; the application in the\u00a0ERASEBKGND\u00a0works for small areas.When\u00a0I need better fixed graphics, I use a third buffer. This way any ERASE\/PAINT will never affect the interface\u00a0output because\u00a0my thread(s) designing is not done &#8230;CopyBufferDC = InterlockedCompareExchange( is thread running )\u00a0== 1 ? BackBufferDC : ThreadBufferDC<\/p>\n<p>BitBlt( FrontBufferDC, CopyBufferDC) &#8230;<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn6 Hi,In my view i have a paint area for circle and next to it are some controls like edit boxes, buttons etc.\u00a0Can 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?<\/p>\n<p>Regards.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn7 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)\u00a0in your window.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn Hi,I am using a SDI &#8211; Application.\u00a0In the Views\u00a0(OnPaint())\u00a0am 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\u00a0do this? [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3965","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3965"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3965\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}