Advertisement Jump to content
Sign in to follow this  
tendifo

Creating a buffer DC

This topic is 4986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!