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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include<windows.h> #include<atlimage.h> BOOL ScreenCapture(); BOOL PaintMouse(HDC hdc); BOOL SaveBmp(HBITMAP bmp); int main() { ScreenCapture();
return 0; }
BOOL ScreenCapture() { HWND hDesktopWnd = GetDesktopWindow(); HDC hdc = GetDC(hDesktopWnd);
HDC mdc = CreateCompatibleDC(hdc);
DWORD dwScreenWidth = GetSystemMetrics(SM_CXSCREEN); DWORD dwScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HBITMAP bmp = CreateCompatibleBitmap(hdc,dwScreenWidth,dwScreenHeight);
HBITMAP holdbmp = (HBITMAP)SelectObject(mdc,bmp); BitBlt(mdc,0,0,dwScreenWidth,dwScreenHeight,hdc,0,0,SRCCOPY);
PaintMouse(mdc); SaveBmp(bmp);
return TRUE; }
BOOL PaintMouse(HDC hdc) { CURSORINFO cursorInfo = {0}; ICONINFO iconInfo = {0}; HBITMAP bmpOldMask = NULL; HDC bufdc = CreateCompatibleDC(hdc); RtlZeroMemory(&iconInfo,sizeof(iconInfo)); cursorInfo.cbSize = sizeof(cursorInfo);
GetCursorInfo(&cursorInfo); GetIconInfo(cursorInfo.hCursor,&iconInfo);
bmpOldMask = (HBITMAP)SelectObject(bufdc,iconInfo.hbmMask); BitBlt(hdc,cursorInfo.ptScreenPos.x,cursorInfo.ptScreenPos.y,20,20,bufdc,0,0,SRCAND);
SelectObject(bufdc,iconInfo.hbmColor); BitBlt(hdc,cursorInfo.ptScreenPos.x,cursorInfo.ptScreenPos.y,20,20,bufdc,0,0,SRCPAINT); SelectObject(bufdc,bmpOldMask); DeleteObject(iconInfo.hbmColor); DeleteObject(iconInfo.hbmMask); DeleteDC(bufdc);
return TRUE; }
BOOL SaveBmp(HBITMAP bmp) { CImage image;
image.Attach(bmp);
image.Save("screenCapture.jpg");
return TRUE; }
|