-
screen capture in c
ok people i am a neewby to c but i do know how to program in it im saying im not an expert but i can use it
any way i want to make a screen captureing program can someone provide me with some source that will copy the screen to the clip board for the user to paste in ms paint
-
Search Google for your answer. There's probably a winapi function which will capture the screen. Look for the keywords: winapi screen capture
-
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());
-
i have another question on this. can the print screen button on the keyboard be used somehow to achieve this?i mean can the button be emulated somehow in a program?