Jump to content
  • Advertisement
Sign in to follow this  
Crayolia

ScreenCapture in C.

This topic is 5123 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!