CMemDC::~CMemDC() { if (!GetSafeHdc()) { return; } if(m_pOldBitmap) { SelectObject(m_pOldBitmap); m_pOldBitmap = NULL; } m_bitmap.DeleteObject(); DeleteDC(); }
BOOL CBitmapDC::CreateBitmapDC(int W, int H) { CWindowDC dc(NULL); CDC *pDC = &dc; if( GetSafeHdc()==NULL ) CreateCompatibleDC( pDC ); else SelectObject( m_pOldBmp ); if( m_bitmap.GetSafeHandle()!= NULL ) m_bitmap.DeleteObject(); if( !m_bitmap . CreateCompatibleBitmap( pDC, W, H ) ) return FALSE; m_pOldBmp = SelectObject( &m_bitmap ); return TRUE; }
void CUImageDC::Create(int nWidth, int nHeight) { BITMAPINFOHEADER bih; memset(&bih, 0, sizeof(BITMAPINFOHEADER)); bih.biSize = sizeof(BITMAPINFOHEADER); bih.biWidth = ((((int)nWidth * 8) + 31) & ~31) >> 3; bih.biHeight = nHeight; bih.biPlanes = 1; bih.biBitCount = 32; bih.biCompression = BI_RGB; m_hBmp = NULL; m_hDC = CreateCompatibleDC(NULL); m_hBmp = ::CreateDIBSection( GetSafeHdc(), (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)(&m_pBits), NULL, 0); SelectObject(m_hDC, m_hBmp); }
void CBitmapDC::Create(int nWidth, int nHeight) { if (nWidth <= 0 || nHeight<= 0) return; if (nWidth != m_DcSize.cx || nHeight != m_DcSize.cy) { Delete(); m_DcSize.cx = nWidth; m_DcSize.cy = nHeight; BITMAPINFOHEADER bih; memset(&bih, 0, sizeof(BITMAPINFOHEADER)); bih.biSize = sizeof(BITMAPINFOHEADER); bih.biHeight = nHeight; bih.biWidth = nWidth; //bih.biWidth = ((((int)nWidth * 8) + 31) & ~31) >> 3; bih.biPlanes = 1; bih.biBitCount = 32; bih.biCompression = BI_RGB; m_hDC = CreateCompatibleDC(NULL); if (m_hDC != NULL) { m_hBmp = ::CreateDIBSection(GetSafeHdc(), (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)(&m_pBits), NULL, 0); if (m_hBmp != NULL && m_pBits != NULL) SelectObject(m_hDC, m_hBmp); else Delete(); } else { Delete(); } } else { if (m_pBits != NULL) memset(m_pBits, 0, m_DcSize.cx * m_DcSize.cy * 4); } }
void CBufferedDC::DestroyObjects() { if( m_nRestorePoint ) { RestoreDC( m_nRestorePoint ); m_nRestorePoint = 0; } // Delete if already created if( m_bmpBuffer.GetSafeHandle()) { m_bmpBuffer.DeleteObject(); }//End if // Delete DC if already created if( GetSafeHdc()) { DeleteDC(); }// End if }// End DestroyObjects