Scrambled graphics with nested buffered components at custom GUI



Hi,
I have implemented a custom GUI library with buffered components.
I used EvC 4.0 (SP4) and this library did work very well, while
compiled for a WinCE 4.2 system. After an Upgrade to WinCE 5.0,
the component's graphics get randomly scrambled and sometimes
disappear at all. I already found a quick fix (by using DIB's instead of
DDB's),
but with the DIB's, text antialiasing doesn't work anymore, so this isn't
really
an acceptable solution. Unfortunately the problem is a little complex, so I
will
post the 4 related methods and their dependencies in the following (left out
as much unimportant stuff as possible).

Actually I was used to code in java, so maybe I just screwed up using
the structures in a miserable way. I really hope someone can help me out.

Thomas


Wnd::OnPaint()
{
CPaintDC dc = CPaintDC(this);
DrawChildren(&dc);
...
}

DrawChildren(CDC* dc)
{
// initialize
CDC memDC;
HBITMAP offscreenBmp;
HGDIOBJ oldObj;

memDC.CreateCompatibleDC(dc);
offscreenBmp = CreateCompatibleBitmap(dc->GetSafeHdc(),...);
oldObj = memDC.SelectObject(offscreenBmp);

// draw the children
for(...)
{
curChild->DrawElement(&memDC);
}

// BitBlt memDC into dc
dc->BitBlt(...,&memDC,...)

// cleanup
memDC.SelectObject(oldObj);
memDC.DeleteDC();
DeleteObject(offscreenBmp);
}

DrawElement(CDC* dc)
{
// initialize
CDC memDC;
CBitmap* bmp;
CBitmap* oldBmp;

memDC.CreateCompatibleDC(dc);
if (IsCached(...))
{
// the cached CBitmaps are stored in a map
bmp = GetCachedBitmap(...)
}else{
bmp = CreateCachedBitmap()
if(HasChildren(...)
{
// recursive call of above function
DrawChildren(&memDC);
}else{
// simply paint the component into the memDC
FinallyDrawElement(&memDC);
}
}
oldBmp = memDC.SelectObject(bmp);

// BitBlt nested DC into parent DC
dc->BitBlt(...,&memDC,...)

// clean up
memDC.SelectObject(oldBmp);
memDC.DeleteDC();
}

CreateCachedBitmap()
{
HDC hDC = ::GetDC(AfxGetMainWnd()->GetSafeHwnd());
HBITMAP myBmp = CreateCompatibleBitmap(hDC, ...);
// This was my quick fix: HBITMAP myBmp = CreateDIBSection(hDC,...);
ReleaseDC(NULL, hDC);
SetCached(true);
}


.