# ScreenCapture in C.

This topic is 5396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, so far my program does the following. 1) Creates a DC 2) Steals a chunk of another windows display and puts it into the DC. 3) Refer to step 4. 4) Where do I go from here? I've read like 10 different articles on how ppl done it, but most are C++ solutions, and others are incredibly huge. 1) I don't want any sort of compression. 2) I only want BITMAP (.bmp) files. Whats a standard C approach to saving a DC to a file? Edit: I'm thinking about including "graphics.h", and than using DDB -> DIB, WriteDIB

##### Share on other sites
Hrm... maybe I'll just use this block of code I found on CodeProject.com. Gotta decypher it first. :S

				BITMAPINFO	bi;				void *pBits=NULL;				int	 nWidth=GetSystemMetrics(SM_CXSCREEN);				int	 nHeight=GetSystemMetrics(SM_CYSCREEN);				ZeroMemory(&bi,sizeof(bi));				bi.bmiHeader.biSize=sizeof(bi.bmiHeader);				bi.bmiHeader.biHeight=nHeight;				bi.bmiHeader.biWidth=nWidth;				bi.bmiHeader.biPlanes=1;				bi.bmiHeader.biBitCount=24;				bi.bmiHeader.biCompression=BI_RGB;				bi.bmiHeader.biSizeImage=3*nWidth*nHeight;				HDC		hBmpFileDC=CreateCompatibleDC(hDesktopCompatibleDC);				HBITMAP	hBmpFileBitmap=CreateDIBSection(hDesktopCompatibleDC,&bi,DIB_RGB_COLORS,&pBits,NULL,0);				SelectObject(hBmpFileDC,hBmpFileBitmap);				BitBlt(hBmpFileDC,0,0,nWidth,nHeight,hDesktopCompatibleDC,0,0,SRCCOPY);                HANDLE	hFile=CreateFile(szFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);				if(hFile!=INVALID_HANDLE_VALUE)				{					DWORD	dwRet=0;					BITMAPFILEHEADER	bmfHeader;					ZeroMemory(&bmfHeader,sizeof(bmfHeader));					bmfHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);					bmfHeader.bfSize=bi.bmiHeader.biSizeImage+bmfHeader.bfOffBits;					bmfHeader.bfType='MB';					WriteFile(hFile,&bmfHeader,sizeof(bmfHeader),&dwRet,NULL);					WriteFile(hFile,&bi.bmiHeader,sizeof(bi.bmiHeader),&dwRet,NULL);					WriteFile(hFile,pBits,bi.bmiHeader.biSizeImage,&dwRet,NULL);					CloseHandle(hFile);				}				DeleteDC(hBmpFileDC);				DeleteObject(hBmpFileBitmap);				SetCursor(LoadCursor(NULL,IDC_ARROW));				break;

##### Share on other sites
When I get home I'll post the code I used. This is one of those things I don't mind sharing complete code for. Normaly I'd just share the process of doing it, but without many snippits of code that wouldn't get you very far (at least it didn't for me). If I'm feeling generous I'll even post some code that will let you convert the bitmap into a jpeg, gif, png, or tiff file (it ain't pretty, or efficient, but it works).

• 21
• 13
• 9
• 17
• 13