Using Bitblt results in black background with just Icon displayed on PPC

Giganews Newsgroups
Subject: Using Bitblt results in black background with just Icon displayed on PPC
Posted by:  Zekai Dis (zeka…@gmail.com)
Date: 29 Dec 2006

Hei,

Although it might not be directly within connection to this group, I
have a problem with bitblt (or at least I think it got something to do
with bitblt :)..I'm a complete newbie so please forgive my ignorance.
We had been using the same approach on a previous release of our mobile
client but when we switched to the new approach(although nothing
remarkable of that sort has changed concerning this issue, just that we
dont use picture for background anymore).

***Below is the part of code that worked in our previous release..

---------------------------------------------------------------------------------------------------------
        CPaintDC dc ( m_hWnd );
        CDC memDC = CreateCompatibleDC (dc);

        CRect r;
        GetClientRect( &r );

        CBitmap memBmp = CreateCompatibleBitmap (dc, r.Width(),
r.Height());
        HGDIOBJ old = SelectObject (memDC, memBmp);
        //DeleteObject(old);

        CBitmap* background =
iBkg;//CtrlAttributeQuery::GetBitmap(EBackground);
        RECT cr;
        GetClientRect(&cr);

        if ( background )
        {
                CGraphics g( memDC, background );
                g.DrawImage( memDC, cr);
        }

        SetBkMode( memDC, TRANSPARENT );

        if (iPhoneIcon)
        {
                CGraphics g( memDC, iPhoneIcon );
                g.DrawImage( memDC, iPhoneIconRect, true );
        }

        iLabel1.Paint(memDC);
        iLabel2.Paint(memDC);

        ::BitBlt(dc, r.left,r.top,r.right,r.bottom, memDC, 0, 0,
SRCCOPY);
        SelectObject(memDC, old);
---------------------------------------------------------------------------------------------------------

****Code(current code) that displays black background even we define it
as white
---------------------------------------------------------------------------------------------------------

        CPaintDC dc ( m_hWnd );

        CDC memDC = CreateCompatibleDC (dc);

        CRect r;
        GetClientRect( &r );

        CBitmap memBmp = CreateCompatibleBitmap (dc, r.Width(),
r.Height());

        HGDIOBJ old = SelectObject (memDC, memBmp);

        CBrush b;
        HBRUSH brush =
b.CreateSolidBrush(CtrlAttributeQuery::GetColor(EDialScreenBkg));

        if ( brush )
        {
                HGDIOBJ bo = ::SelectObject( dc, b );

                memDC.FillRect(&r,brush);

                ::SelectObject( dc, bo );
        }

        if ( brush ) b.DeleteObject();

        SetBkMode( memDC, TRANSPARENT );

        if (iPhoneIcon)
        {
                CGraphics g( memDC, iPhoneIcon );
                g.DrawImage( memDC, iPhoneIconRect, true );
        }

        iLabel1.Paint(memDC);
        iLabel2.Paint(memDC);

        ::BitBlt(dc, r.left,r.top,r.right,r.bottom, memDC, 0, 0,
SRCCOPY);
        SelectObject(memDC, old);

        return 0;
---------------------------------------------------------------------------------------------------------
As you see the only visible difference is that we dont use a
picture/bitmap for
background in current release. While debugging
though, I see that until Bitblt runs, we see a white background(that
happens after CPaintDC dc ( m_hWnd ); )) with a
black rect where the button should be. But after bitblt runs, only icon
is displayed and background becomes complete black.  Any kind of advice
appreciated. Should I use SetBkColor or something like that?. Am I
doing the right thing in using Brush in that way? Thanks in advance and
happy 2007 everybody.

Cheers :)

Replies