Flicker drawing owner drawn controls...

Flicker drawing owner drawn controls...

Post by chandu.nit » Fri, 13 Feb 2009 03:54:25

I have a main window with two children(say child1 and child2 )
clipping it's entire area. One of children(child2 ) windows contains
child controls.
|---------------------------| This is child 1
| --------------------------|
| | This is child 2
| |
These controls are owner drawn(set by BS_OWNERDRAW ) capturing
WM_DRAWITEM in the window message handler (of child2 ).

Problem is that now my second child window(child2) flickers whenever
it is activated or some other top level window is moved over it.

Although it never causes flicker when I move it

I have used double buffering(off screen dc) and am returning TRUE in
WM_ERASEBKGND message to reduce the flicker in all window drawings.

I have used WS_CLIPCHILDREN WS_CLIPSIBLINGS for the windows(child1 and
child2) which in turn contain more owner drawn child controls.

Here is how my custom control draw looks like

HDC memDC = CreateCompatibleDC(data.hDC);
HBITMAP hMemBmp = CreateCompatibleBitmap(data.hDC, destWidth,
HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC, hMemBmp);

Graphics* pCanvas = Graphics::FromHDC(memDC)

//Drawing is done here on pCanvas

BitBlt(data.hDC, 0, 0, destWidth, destHeight, memDC, 0, 0, SRCCOPY);

//Always select the old bitmap back into the device context
SelectObject(memDC, hOldBmp);

Could any one please suggest a solution for the same?

Flicker drawing owner drawn controls...

Post by Seethara » Sat, 14 Feb 2009 01:11:32

Does your "child2" have WS_CLIPCHILDREN style set? You mentioned
returning true from EraseBackground, but from where? Your main
application or "child2" window?



Flicker drawing owner drawn controls...

Post by chandu.nit » Sat, 14 Feb 2009 03:42:50

Yes child2 has WS_CLIPCHILDREN set. I have set this for every window
which contains child controls/child windows. I am returning true from
wm_erasebkgnd from all the window message handlers.
But for controls which are drawn from with in WM_DRAWITEM, i am not
able to find a way to override Wm_erasebkgnd message.
Is it the real culprit?