Link to home
Start Free TrialLog in
Avatar of kjc1111
kjc1111

asked on

Copy CView contents to a bitmap

I'd like to create a bitmap copy of the current contents of my CView, which may or may not be currently visible on the screen. Here is the code I've added to my OnDraw function:

void
MyView::OnDraw
(
    CDC* pDC
)
{

    ... normal processing ...

    // Copy the view contents to a bitmap.

    CDC dc;
    dc.CreateCompatibleDC( pDC );

    if ( m_pBitmap != NULL )
    {
        delete m_pBitmap;
    }

    m_pBitmap = new CBitmap();
    m_pBitmap->CreateCompatibleBitmap( &dc, szView.cx, szView.cy );

    CBitmap* pOld = ( CBitmap* )dc.SelectObject( m_pBitmap );
    dc.BitBlt( 0, 0, szView.cx, szView.cy, pDC, 0, 0, SRCCOPY );
    dc.SelectObject( pOld );

}
But now when I examine the bitmap I can see that there is only 1 bit per pixel. I'm sure I'm missing something, can anyone help?

Thanks, Kevin
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kjc1111
kjc1111

ASKER

Thanks Sara, that worked great!

Kevin