Automatic double buff and blit to screen
I have a graphics class that encapsulates BitBlt. I use it like this:
Code:
case WM_PAINT:
{
PAINTSTRUCT lpPaintStruct;
HDC hdc= ::BeginPaint(Form.Handle, &lpPaintStruct);
a::graphics g(hdc, &lpPaintStruct.rcPaint);
g.DrawImage(Form.Handle, &abmp, &lpPaintStruct.rcPaint, &lpPaintStruct.rcPaint);
g.DrawImage(Form.Handle, &abmp, &drawRect, true);
g.Show(); //blits the memDC to screen.
::EndPaint(Form.Handle, &lpPaintStruct);
break;
}
The graphics constructor:
Code:
graphics(HDC hdc, RECT* invalRect)
{
this->invalLocation= *invalRect;
this->hdc= hdc;
this->memDC= ::CreateCompatibleDC(hdc);
this->hMemBmp= ::CreateCompatibleBitmap(hdc, invalLocation.right-invalLocation.left, invalLocation.bottom-invalLocation.top);
::SelectObject(memDC, hMemBmp);
}
The constructor code is used for double buffing.
The issue with doing it this way is that I have to call Show() to blit the memDC to the screen.
I tried putting the Show() code in the destructor but by that time blitting fails because the members are NULL.
Is there any way my graphics class can automatically know when Painting is finished?
Note: the only reason I am asking this is because that is the way C# works. Everything is automatically buffed and sent to the screen.:afrog: