Sign in to follow this  

ScreenCapture in C.

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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).

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this