Code:
void Bitmaps::Init(HWND hw )
{
init=true;
hwnd = hw;
windowRect = new RECT;
GetClientRect(hwnd, windowRect );
hdc = GetDC(hwnd );
hdcBuf = CreateCompatibleDC(hdc );
hdcMem = CreateCompatibleDC(hdcBuf );
hbmBackBM = CreateCompatibleBitmap(hdc, windowRect->right, windowRect->bottom );
hbmOldBackBM = (HBITMAP)SelectObject(hdcBuf, hbmBackBM );
BitBlt(hdcBuf, 0, 0, windowRect->right, windowRect->bottom, NULL, 0, 0, BLACKNESS );
BitBlt(hdc, 0, 0, windowRect->right, windowRect->bottom, NULL, 0, 0, BLACKNESS );
}
void Bitmaps::BlitImage(
int imageX,
int imageY,
HBITMAP hbmImage,
bool erase)
{
oldBitmap = (HBITMAP)SelectObject(hdcMem, hbmImage);
if(erase)
BitBlt(hdcBuf, imageX, imageY, windowRect->right, windowRect->bottom, hdcMem, 0, 0, SRCAND);
else
BitBlt(hdcBuf, imageX, imageY, windowRect->right, windowRect->bottom, hdcMem, 0, 0, SRCPAINT);
SelectObject(hdcMem, oldBitmap);
}
void Bitmaps::SwapBuffers()
{
BitBlt(hdc, 0, 0, windowRect->right, windowRect->bottom, hdcBuf, 0, 0, SRCCOPY );
BitBlt(hdcBuf, 0, 0, windowRect->right, windowRect->bottom, NULL, 0, 0, BLACKNESS );
}
Bitmaps::~Bitmaps()
{
if(init)
{
SelectObject(hdcBuf, hbmOldBackBM );
DeleteObject(hbmBackBM );
ReleaseDC(hwnd, hdcBuf );
ReleaseDC(hwnd, hdcMem );
ReleaseDC(hwnd, hdc );
delete windowRect;
}
}
Explain to me what's wrong with this. You're being too abstract for me; where exactly am I using the same DC to do two things?