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…
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?
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.
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.
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.