CDC *pdc = GetDC();
HBITMAP hBitmap = NULL;
if ( pdc )
{
/**
* 创建位图段
*/
BITMAPINFO bmi;
LPBYTE pBits;
ZeroMemory(&bmi, sizeof(bmi));
CRect rcClient;
GetClientRect( rcClient);
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = rcClient.Width();
bmi.bmiHeader.biHeight = rcClient.Height();
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
hBitmap = CreateDIBSection( pdc-> m_hDC,&bmi,DIB_RGB_COLORS,(void **)&pBits,0,0 );
/**
* 创建兼容dc并选择位图段
*/
CDC dcMem;
dcMem.CreateCompatibleDC( pdc);
dcMem.SelectObject( hBitmap );
/**
* 在内存dc上(即位图段上)绘图
* 此函数你自己把你的绘制代码拿出来做成函数 void Paint( CDC *pDC)就行了
*/
dcMem.BitBlt(0,0,rcClient.Width(),rcClient.Height(), pdc,0,0,SRCCOPY);
/**
* 释放dc
*/
ReleaseDC( pdc );
}
/**
* 保存位图
*/
if( hBitmap )
{
CImage img;
img.Attach( hBitmap );
img.Save( "c:\\1.bmp ");
DeleteObject( hBitmap );