분류 | 게시판 |
베스트 |
|
유머 |
|
이야기 |
|
이슈 |
|
생활 |
|
취미 |
|
학술 |
|
방송연예 |
|
방송프로그램 |
|
디지털 |
|
스포츠 |
|
야구팀 |
|
게임1 |
|
게임2 |
|
기타 |
|
운영 |
|
임시게시판 |
|
옵션 |
|
1 2 3 | #define HookingWindowName L"123.jpg-Windows 사진 뷰어" CaptureAnImage(hWnd, HookingWindowName); | cs |
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | int CaptureAnImage(HWND hWnd, LPCWSTR hDisplayId) { HWND hWndCalc; HDC hdcScreen; HDC hdcWindow; HDC hdcMemDC = NULL; HBITMAP hbmScreen = NULL; BITMAP bmpScreen; // Retrieve the handle to a display device context for the client // area of the window. hdcScreen = GetDC(NULL); hWndCalc = FindWindow(NULL, hDisplayId); hdcWindow = GetDC(hWndCalc); // Create a compatible DC which is used in a BitBlt from the window DC hdcMemDC = CreateCompatibleDC(hdcWindow); if (!hdcMemDC) { MessageBox(hWnd, L"CreateCompatibleDC has failed", L"Failed", MB_OK); goto done; } // Get the client area for size calculation RECT rcClient; GetClientRect(hWnd, &rcClient); //This is the best stretch mode SetStretchBltMode(hdcWindow, HALFTONE); //The source DC is the entire screen and the destination DC is the current window (HWND) if (!StretchBlt(hdcWindow,0, 0,rcClient.right, rcClient.bottom,hdcScreen,0, 0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SRCCOPY)) { MessageBox(hWnd, L"StretchBlt has failed", L"Failed", MB_OK); goto done; } // Create a compatible bitmap from the Window DC hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top); if (!hbmScreen) { MessageBox(hWnd, L"CreateCompatibleBitmap Failed", L"Failed", MB_OK); goto done; } // Select the compatible bitmap into the compatible memory DC. SelectObject(hdcMemDC, hbmScreen); // Bit block transfer into our compatible memory DC. if (!BitBlt(hdcMemDC,0, 0,rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,hdcWindow,0, 0,SRCCOPY)) { MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK); goto done; } // Get the BITMAP from the HBITMAP GetObject(hbmScreen, sizeof(BITMAP), &bmpScreen); BITMAPFILEHEADER bmfHeader; BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = rcClient.right - rcClient.left; //bmpScreen.bmWidth; bi.biHeight = rcClient.bottom - rcClient.top, hdcWindow; //bmpScreen.bmHeight; bi.biPlanes = 1; bi.biBitCount = 32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight; // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc // have greater overhead than HeapAlloc. HANDLE hDIB = GlobalAlloc(GHND, dwBmpSize); char *lpbitmap = (char *)GlobalLock(hDIB); // Gets the "bits" from the bitmap and copies them into a buffer // which is pointed to by lpbitmap. GetDIBits(hdcWindow, hbmScreen, 0,(UINT)bmpScreen.bmHeight,lpbitmap,(BITMAPINFO *)&bi, DIB_RGB_COLORS); // A file is created, this is where we will save the screen capture. HANDLE hFile = CreateFile(L"captureqwsx.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); // Add the size of the headers to the size of the bitmap to get the total file size DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); //Offset to where the actual bitmap bits start. bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER); //Size of the file bmfHeader.bfSize = dwSizeofDIB; //bfType must always be BM for Bitmaps bmfHeader.bfType = 0x4D42; //BM DWORD dwBytesWritten = 0; WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL); //Unlock and Free the DIB from the heap GlobalUnlock(hDIB); GlobalFree(hDIB); //Close the handle for the file that was created CloseHandle(hFile); //Clean up done: DeleteObject(hbmScreen); DeleteObject(hdcMemDC); ReleaseDC(NULL, hdcScreen); ReleaseDC(hWnd, hdcWindow); return 0; } | cs |
죄송합니다. 댓글 작성은 회원만 가능합니다.
번호 | 제 목 | 이름 | 날짜 | 조회 | 추천 | |||||
---|---|---|---|---|---|---|---|---|---|---|
63 | 정신나간 알고리즘 [6] | 대★맛이야 | 16/02/12 20:43 | 49 | 7 | |||||
62 | 최근 전적 | 대★맛이야 | 16/02/11 20:34 | 18 | 0 | |||||
61 | 영화같은 칼질 [6] | 대★맛이야 | 16/02/08 13:24 | 48 | 6 | |||||
60 | 슬픈나무 [3] | 대★맛이야 | 16/02/08 13:20 | 165 | 3 | |||||
59 | 배필 샀습니다. [7] | 대★맛이야 | 15/12/28 01:55 | 24 | 1 | |||||
58 | =화장 [2] | 대★맛이야 | 15/12/18 10:39 | 123 | 6 | |||||
57 | 메리 크리스마스 | 대★맛이야 | 15/12/14 12:52 | 126 | 4 | |||||
56 | 섭분들을 위한 Anti bad language 플러그인 AntiBL [3] | 대★맛이야 | 15/12/10 21:07 | 19 | 4 | |||||
55 | 전쟁을 끝내는 방법 [3] | 대★맛이야 | 15/12/01 23:43 | 81 | 12 | |||||
54 | 학교 시험문제 질문입니다. [3] | 대★맛이야 | 15/11/19 20:05 | 27 | 0 | |||||
53 | php 질문 있습니다. [1] | 대★맛이야 | 15/11/12 22:47 | 18 | 0 | |||||
52 | FM 한국 지역락 풀렷네요 [2] | 대★맛이야 | 15/10/24 23:39 | 111 | 1 | |||||
51 | 발록 대거 [8] | 대★맛이야 | 15/09/12 22:25 | 25 | 10 | |||||
50 | 게임 할인 정보 [6] | 대★맛이야 | 15/08/07 16:38 | 161 | 7 | |||||
49 | opencv 릴리즈 모드에 관련해서 [2] | 대★맛이야 | 15/06/12 23:02 | 13 | 0 | |||||
48 | 아래 이미지 캡쳐하는데 짤린다고 한 사람임요 | 대★맛이야 | 15/06/10 21:32 | 22 | 0 | |||||
▶ | 이미지 비교에 관한 고찰 [3] | 대★맛이야 | 15/06/09 23:25 | 39 | 0 | |||||
46 | WIN32 초보적 질문 [4] | 대★맛이야 | 15/06/09 00:41 | 26 | 0 | |||||
45 | opencv 문제 [2] | 대★맛이야 | 15/06/08 00:57 | 25 | 0 | |||||
44 | C++ WINAPI 코딩에 질문 있습니다. [8] | 대★맛이야 | 15/06/06 18:34 | 27 | 3 | |||||
43 | 일단 프로그래머 공부 관련 질문이니까 프로그래머 게시판에 올려여 [3] | 대★맛이야 | 15/06/03 01:16 | 45 | 0 | |||||
42 | 여성부일침, 게임음악 플래시몹 '이번엔 Warriors다' [7] | 대★맛이야 | 15/05/31 12:26 | 214 | 12 | |||||
41 | system("cls"); [1] | 대★맛이야 | 15/04/29 02:06 | 49 | 0 | |||||
40 | ASD12-EWWAL-VBLMZ [5] | 대★맛이야 | 15/01/30 18:44 | 156 | 11 | |||||
39 | [사이다 주의] 라이엇이 칼을 빼들었습니다. [9] | 대★맛이야 | 15/01/30 16:21 | 355 | 10 | |||||
38 | [지갑주의] G2A에서 게임을 세일합니다. [10] | 대★맛이야 | 15/01/14 22:03 | 185 | 7 | |||||
37 | 굇수 목격담 [11] | 대★맛이야 | 15/01/05 21:59 | 30 | 3 | |||||
36 | 배필3를 다시 해봤습니다. [1] | 대★맛이야 | 14/12/13 01:13 | 24 | 0 | |||||
35 | [cs:go] 글옴 매치가 있단 소식에 5일에 걸쳐 다 봤네요 [5] | 대★맛이야 | 14/12/08 23:40 | 87 | 1 | |||||
34 | 컴퓨터 정지현상 [1] | 대★맛이야 | 14/09/09 18:32 | 40 | 0 | |||||
|
||||||||||
[1] [2] [3] [4] | ||||||||||