How can I take a screenshot of the current screen using Win32?
Press Ctrl + PrtScn keys. The entire screen changes to gray including the open menu. Select Mode, or in earlier versions of Windows, select the arrow next to the New button. Select the kind of snip you want, and then select the area of the screen capture that you want to capture.
Take a scrolling screenshot Important: These steps work only on Android 12, on most screens that allow you to scroll. Open the screen that you want to capture. Press the Power and Volume down buttons at the same time. At the bottom, tap Capture more.
The easiest way to take a screenshot on Windows 10 or Windows 11 is with the Print Screen (PrtScn) key. To capture your entire screen, simply press PrtScn on the upper-right side of your keyboard. In Windows 10, the screenshot will be copied to your clipboard.
HDC hScreenDC = GetDC(nullptr); // CreateDC("DISPLAY",nullptr,nullptr,nullptr); HDC hMemoryDC = CreateCompatibleDC(hScreenDC); int width = GetDeviceCaps(hScreenDC,HORZRES); int height = GetDeviceCaps(hScreenDC,VERTRES); HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC,width,height); HBITMAP hOldBitmap = static_cast<HBITMAP>(SelectObject(hMemoryDC,hBitmap)); BitBlt(hMemoryDC,0,0,width,height,hScreenDC,0,0,SRCCOPY); hBitmap = static_cast<HBITMAP>(SelectObject(hMemoryDC,hOldBitmap)); DeleteDC(hMemoryDC); DeleteDC(hScreenDC);
GetDC(NULL);
to get a DC for the entire screen. CreateCompatibleDC
to create a DC compatible with the screen DC.CreateCompatibleBitmap
to create a bitmap compatible with the screen DC to hold the result.SelectObject
to select the compatible bitmap into the compatible DC.BitBlt
to copy from the screen DC to the compatible DC.SelectObject
to deselect the compatible bitmap from the compatible DC.DeleteDC
to delete the compatible DC.When you create the compatible bitmap, you want it compatible with the screen DC, not the compatible DC.
For example:
HDC dcScreen = GetDC(0); HDC dcTarget = CreateCompatibleDC(dcScreen); HBITMAP bmpTarget = CreateCompatibleBitmap(dcScreen); HGDIOBJ oldBmp = SelectObject(dcTarget, bmpTarget); BitBlt(dcTarget, 0, 0, cx, cy, dcDesktop, x, y, SRCCOPY | CAPTUREBLT); SelectObject(dcTarget, oldBmp); DeleteDC(dcTarget); ReleaseDC(dcScreen);
The other important part is to get the size, and location, of the entire virtual screen:
int x = GetSystemMetrics(SM_XVIRTUALSCREEN); //left (e.g. -1024) int y = GetSystemMetrics(SM_YVIRTUALSCREEN); //top (e.g. -34) int cx = GetSystemMetrics(SM_CXVIRTUALSCREEN); //entire width (e.g. 2704) int cy = GetSystemMetrics(SM_CYVIRTUALSCREEN); //entire height (e.g. 1050)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With