- HOME
- Post in | c/c++/winapi
- Post at | 2013. 2. 15. 14:41 | by 밀크빵.
- View comment
활성화된 화면 캡쳐 ScreenCapture
HBITMAP ScreenCapture(HWND hWnd)
{
HDC hScrDC, hMemDC;
HBITMAP hBitmap;
RECT rt;
GetWindowRect(GetForegroundWindow(), &rt);
// GetWindowRect(GetActiveWindow(), &rt);
rt.left = max(0, rt.left);
rt.right = min(rt.right, GetSystemMetrics(SM_CXSCREEN));
rt.top = max(0, rt.top);
rt.bottom = min(rt.bottom, GetSystemMetrics(SM_CYSCREEN));
hScrDC=CreateDC("DISPLAY",NULL,NULL,NULL);
hMemDC = CreateCompatibleDC(hScrDC);
hBitmap = CreateCompatibleBitmap(hScrDC, rt.right-rt.left, rt.bottom-rt.top);
SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, rt.right-rt.left, rt.bottom-rt.top, hScrDC, rt.left, rt.top, SRCCOPY);
DeleteDC(hMemDC);
DeleteDC(hScrDC);
InvalidateRect(hWnd, NULL, TRUE);
return hBitmap;
}
==================================================================================================
위의 함수를 호출하여 사용한다
핫키를 등록하여 Ctrl + F4가 눌리면 화면 캡쳐!
WM_PAINT에서 캡쳐된 화면을 그려줌
case WM_CREATE:
RegisterHotKey(hWnd, 0, MOD_CONTROL, VK_F4);
break;
case WM_HOTKEY:
hBit = ScreenCapture(hWnd); // CTRL +F4
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
if(hBit != NULL)
{
hMemDC = CreateCompatibleDC(hdc);
SelectObject(hMemDC, hBit);
GetObject(hBit, sizeof(BITMAP), &bmp);
BitBlt(hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
}
EndPaint(hWnd, &ps);
return 0;
====================================================================================
'c/c++ > winapi' 카테고리의 다른 글
API _ 선, 박스, 도형 그리기 (0) | 2013.02.20 |
---|---|
Win32 프로젝트를 빈프로젝트로 생성하여 DialogBox 띄우기 (0) | 2013.02.18 |
[winapi] 파일 선택 다이얼로그 띄우기 (0) | 2012.12.17 |
[winapi]OWNER DRAW로 여러 버튼 그려주기 (0) | 2012.12.13 |
HINSTANCE HWND 차이 (0) | 2012.11.26 |