-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathss.cpp
35 lines (24 loc) · 959 Bytes
/
ss.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <windows.h>
#include <iostream>
using namespace std;
int main() {
// Get a device context for the entire screen.
HDC hdcScreen = GetDC(NULL);
// Create a compatible device context.
HDC hdcMem = CreateCompatibleDC(hdcScreen);
// Create a compatible bitmap.
HBITMAP bmp = CreateCompatibleBitmap(hdcScreen, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
// Select the compatible bitmap into the compatible device context.
SelectObject(hdcMem, bmp);
// Copy the screen to the compatible bitmap.
BitBlt(hdcMem, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), hdcScreen, 0, 0, SRCCOPY);
// Save the compatible bitmap to a file.
SaveDCSnapshot(bmp, "screenshot.bmp");
// Delete the compatible bitmap.
DeleteObject(bmp);
// Delete the compatible device context.
DeleteDC(hdcMem);
// Release the device context for the entire screen.
ReleaseDC(NULL, hdcScreen);
return 0;
}