This function captures any window on screen and saves it to the clipboard:
Code:
#define RectWidth(lprc) ((lprc)->right-(lprc)->left)
#define RectHeight(lprc) ((lprc)->bottom-(lprc)->top)
void CaptureWindow(HWND hwnd){
HDC hdc,hdcMem;
HBITMAP hbm,oldbm;
RECT rc,rcCrop;
hdc=GetWindowDC(hwnd);
hdcMem=CreateCompatibleDC(hdc);
SelectBitmap(hdcMem,oldbm);
GetWindowRect(hwnd,&rc);
SetRect(&rcCrop,0,0,RectWidth(&rc),RectHeight(&rc));
hbm=CreateCompatibleBitmap(hdc,RectWidth(&rcCrop),
RectHeight(&rcCrop));
oldbm=SelectObject(hdcMem,hbm);
BitBlt(hdcMem,0,0,RectWidth(&rcCrop),
RectHeight(&rcCrop),hdc,0,0,SRCCOPY);
OpenClipboard(hwnd);
EmptyClipboard();
SetClipboardData(CF_BITMAP,hbm);
CloseClipboard();
ReleaseDC(hwnd,hdc);
DeleteDC(hdcMem);
DeleteObject(oldbm);
}
To capture the screen, call:
CaptureWindow(GetDesktopWindow());