Taking Screenshots in Windows Applications with Win32
Capturing the current screen display is a common need in application development. In Windows, this can be achieved efficiently using Win32's Graphics Device Interface (GDI) functions.
Solution
The following code snippet demonstrates how to take a screenshot using Win32:
HDC hScreenDC = GetDC(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);
Explanation
The above is the detailed content of How to Capture Screenshots of Windows Applications Using Win32 GDI?. For more information, please follow other related articles on the PHP Chinese website!