Creating a buffer DC
How can I make a buffer DC in C++ where I can draw to it and then BitBlt it to the screen?
Like
MoveToEx(bufferDC, 0, 0, NULL);
LineTo(bufferDC, 100, 100);
BitBlt(hDC, 0, 0, 100, 100, bufferDC, 0, 0, SRCCOPY)
Thanks
In your initialization section
HWND hwnd;
HDC hdc;
HDC mdc;
RECT rect;
HBITMAP hbmp;
HGDIOBJ obmp;
hdc = GetDC(hwnd);
mdc = CreateCompatibleDC(hdc);
GetClientRect(hwnd, &rect);
hbmp = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
obmp = SelectObject(mdc, hbmp);
In your resizing section
SelectObject(mdc, obmp);
DeleteObject(hbmp);
hbmp = CreateCompatibleBitmap(hdc, new_width, new_height);
obmp = SelectObject(mdc, hbmp);
In your cleanup section
SelectObject(mdc, obmp);
DeleteObject(hbmp);
DeleteDC(mdc);
ReleaseDC(hwnd, hdc);
Any drawing you should do to the mdc, and when your repainting the screen all you need to do is BitBlt from the mdc to the hdc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement