# Win32 API question-- eliminating flickering in controls

**URL:** <https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559>\
**Category:** Factual Questions\
**Created:** [January 9, 2004, 2:43am UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559 "2004-01-09T02:43:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dre2xl](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@dre2xl](https://boards.straightdope.com/u/dre2xl)\
**Post date:** [January 9, 2004, 2:43am UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559/1 "2004-01-09T02:43:11Z")

</div>

I’m new to Win32 and Google doesn’t offer much help on this particular question.

I overrid WM\_ERASEBKGND and implemented double buffering in WM\_PAINT to some success–the actual window/dialog itself doesn’t flicker.

However the controls–buttons, trackbar, etc.–still flicker. Any way to eliminate the flickering?

I tried doing NM\_CUSTOMDRAW to make a double-buffered, custom-drawn trackbar while putting a CDRF\_SKIPDEFAULT in the CDDS\_PREERASE stage, but that doesn’t work, the trackbar goes ahead and erases itself anyway. (Although, the trackbar does look a durn lot prettier…)

And I can’t find a way to reach the erase stage in owner-drawn buttons/etc. I’m a perfectionist and this really bugs me…

---

<div class="post-metadata">

**Author:** ![Ms2001](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ms2001/32/18463_2.png) [@Ms2001](https://boards.straightdope.com/u/Ms2001)\
**Post date:** [January 9, 2004, 3:39am UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559/2 "2004-01-09T03:39:36Z")

</div>

WM\_ERASEBKGND is probably the culprit. You’re overriding it for your form, but the controls still handle it themselves when they repaint. You might have to subclass the buttons or hook into their window procedures to make them ignore WM\_ERASEBKGND.

Why are you redrawing the window so often that the flickering is noticable? 😉

---

<div class="post-metadata">

**Author:** ![dre2xl](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@dre2xl](https://boards.straightdope.com/u/dre2xl)\
**Post date:** [January 9, 2004, 4:44am UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559/3 "2004-01-09T04:44:05Z")

</div>

Alrighty, understood, thanks, I think might I know how to do just that now–will let you know if it works tomorrow.

As for why it’s being redrawn it so often–I’m making a color selector–there are 4 taskbars, each taskbar corresponding to R/G/B/A components.

The color selector is working great, it’s just that I want the color to be automatically updated _while_ I drag the taskbar rather than call for a repaint after dragging.

---

<div class="post-metadata">

**Author:** ![dre2xl](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@dre2xl](https://boards.straightdope.com/u/dre2xl)\
**Post date:** [January 9, 2004, 4:45am UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559/4 "2004-01-09T04:45:19Z")

</div>

That should be trackbar, not taskbar. Dhurr.

---

<div class="post-metadata">

**Author:** ![dre2xl](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@dre2xl](https://boards.straightdope.com/u/dre2xl)\
**Post date:** [January 9, 2004, 11:12pm UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559/5 "2004-01-09T23:12:14Z")

</div>

A combination of subclassing and setting WS\_CLIPCHILDREN worked, thanks… subclassing to WM\_PAINT instead of NM\_CUSTOMDRAW had the added advantage of being able to change the background color! So now I’ve got a very pretty color picker, flicker-free!

I didn’t even have to use MFC (Win32 API is enough of a challenge as it is)–I think when the project’s done I’ll put up a Win32 page for complete idiots like me.

---

<div class="post-metadata">

**Author:** ![Trigonal\_Planar](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@Trigonal\_Planar](https://boards.straightdope.com/u/Trigonal_Planar)\
**Post date:** [January 10, 2004, 12:14am UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559/6 "2004-01-10T00:14:43Z")

</div>

If I’m correct, you shouldn’t ever have to use MFC. MFC just provides wrapper functions to, ahem, “simplify” API implementation.

---

<div class="post-metadata">

**Author:** ![dre2xl](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@dre2xl](https://boards.straightdope.com/u/dre2xl)\
**Post date:** [January 10, 2004, 1:17am UTC](https://boards.straightdope.com/t/win32-api-question-eliminating-flickering-in-controls/223559/7 "2004-01-10T01:17:52Z")

</div>

MFC SIMPLIFIES the Win32 API? _insert Pit-worthy rant here on MS and MFC here_ Thanks, though… glad to know no one’s missing out on anything by sticking with the Win32 API.
