Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / MFC
Article

Fast screen, window, region and print screen capture

Rate me:
Please Sign up or sign in to vote.
1.39/5 (73 votes)
4 Dec 2002CPOL 335.4K   5K   67   64
Screen Snaper is an fast screen, window, region and print screen capture

Sample Image - ScreenSnaper.gif

Introduction

Screen Snaper is an simple application for Screen capture and snapshot. The application use exported function from library SnaperHelper.dll compatible with VC, VB, Delphi and other languages that can use DLL.

Snapshot features

  • Get Desktop window
  • Get Window on the Desktop
  • Get Region of the desktop
  • Trap Print Screen key

In Window and Region capture mode, an helper show the zoomed position under the cursor and the current color. These modes also include keys shortcut and pop menu to permit switch between mode and much more...

About demo

This demo application include source code for clients in VC and VB. The source code of library SnaperHelper.dll is not provided.

History

  • 8 december 2002 - Demo project updated. Now include missing SnaperHelper.lib and SnaperHelperLib.h.

Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Canada Canada

Comments and Discussions

 
GeneralPrinting a Screen capture in C# Pin
Anonymous26-Jan-05 15:41
Anonymous26-Jan-05 15:41 
GeneralDemo Update For MSVS .NET 2003 (VB And C#) Pin
DCUtility13-Nov-04 16:44
professionalDCUtility13-Nov-04 16:44 
GeneralFixing the region Pin
Won Huh24-Oct-04 21:15
sussWon Huh24-Oct-04 21:15 
GeneralScreen capture fails for multiple instances Pin
vishalmore4-Oct-04 23:33
vishalmore4-Oct-04 23:33 
GeneralScreen capture Pin
angello16-Jun-04 4:06
angello16-Jun-04 4:06 
GeneralRe: Screen capture Pin
Anonymous1-Aug-04 0:09
Anonymous1-Aug-04 0:09 
GeneralRe: Screen capture Pin
Member 16179999-Jan-05 11:21
Member 16179999-Jan-05 11:21 
GeneralRe: Screen capture Pin
Shaheed Legion25-May-06 23:54
Shaheed Legion25-May-06 23:54 
GeneralRe: Screen capture Pin
Shaheed Legion27-Nov-06 1:41
Shaheed Legion27-Nov-06 1:41 
Hi , I have a good way for you to get a hold of the screen.... :
this method has worked for me without fail , for more than a year now ,
and Im still waiting to find a pc that won't be able to perform this function Smile | :)

To use it simply add the forward declaration (prototype) at the top of your file :
int SnapShot(char* fname);

And then , when you want to use it , simply call it with a file name :
<br />
{<br />
//.......some code<br />
SnapShot("img0.bmp");<br />
//.......some code<br />
}<br />
 <br />
int SnapShot(char* fname)<br />
{<br />
HBITMAP hdib;<br />
BITMAPINFO bi;<br />
BITMAPFILEHEADER bfh;<br />
void *bits; // the dib information...<br />
bits=NULL;<br />
<br />
int WIDTH,HEIGHT,BPP;<br />
WIDTH = GetSystemMetrics(SM_CXSCREEN);<br />
HEIGHT=GetSystemMetrics(SM_CYSCREEN);<br />
BPP = 24; <br />
//you can use GetSystemMetrics(SM_BITSPERPEL); <br />
// for this call , but i like to use one<br />
//uniform standard for all my dibs :)<br />
<br />
bi.bmiHeader.biSize = 40;<br />
bi.bmiHeader.biWidth = WIDTH;<br />
bi.bmiHeader.biHeight = HEIGHT;<br />
bi.bmiHeader.biPlanes = 1;<br />
bi.bmiHeader.biBitCount = BPP;<br />
bi.bmiHeader.biCompression = BI_RGB;<br />
bi.bmiHeader.biSizeImage = (BPP/8)*(WIDTH)*(HEIGHT);<br />
bi.bmiHeader.biXPelsPerMeter =0;<br />
bi.bmiHeader.biYPelsPerMeter =0;<br />
bi.bmiHeader.biClrUsed =0;<br />
bi.bmiHeader.biClrImportant =0;<br />
<br />
bfh.bfType = 0x4D42;<br />
bfh.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);<br />
bfh.bfSize = bi.bmiHeader.biSizeImage+bfh.bfOffBits;<br />
bfh.bfReserved1 = 0;<br />
bfh.bfReserved2 = 0;<br />
<br />
HDC hdc = GetDCEx (hWnd,NULL, DCX_CACHE|DCX_LOCKWINDOWUPDATE) ;<br />
HDC fdc = CreateCompatibleDC(hdc);<br />
<br />
hdib = CreateDIBSection(fdc,&bi,DIB_RGB_COLORS,&bits,NULL,0);<br />
    SelectObject(fdc,hdib);<br />
BitBlt(fdc,0,0,WIDTH,HEIGHT,hImgDC,0,0,SRCCOPY);<br />
ReleaseDC(hWnd,hdc); <br />
<br />
 <br />
<br />
//this creates a directory called "snapshots" <br />
//and tells the user what's happening<br />
<br />
char firstpath[255];<br />
GetCurrentDirectory(255,firstpath);<br />
if(SetCurrentDirectory("SnapShots") == 0)<br />
CreateDirectory("SnapShots",NULL); <br />
SetCurrentDirectory(firstpath);<br />
<br />
char *tempbuffer=malloc(sizeof(char)*255);<br />
sprintf(tempbuffer,"%s\\SnapShots\\%s",firstpath,fname);<br />
<br />
MessageBox(NULL,tempbuffer,"Creating...",MB_OK);<br />
<br />
BOOL bSuccess = FALSE ;<br />
DWORD dwBytesWritten ;<br />
HANDLE hFile ;<br />
hFile = CreateFile (tempbuffer, GENERIC_WRITE,FILE_SHARE_WRITE, NULL,<br />
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) ; <br />
if (hFile == INVALID_HANDLE_VALUE)<br />
return FALSE ;<br />
bSuccess = WriteFile (hFile,&bfh,sizeof(bfh), &dwBytesWritten, NULL) ;<br />
<br />
bSuccess = WriteFile (hFile,&bi.bmiHeader,sizeof(bi.bmiHeader), &dwBytesWritten, NULL) ;<br />
<br />
bSuccess = WriteFile (hFile,bits,bi.bmiHeader.biSizeImage, &dwBytesWritten, NULL) ;<br />
<br />
CloseHandle (hFile) ;<br />
DeleteDC(fdc);<br />
DeleteObject(hdib);<br />
free(tempbuffer);<br />
return TRUE;<br />
}<br />



The tears shed in vain
and the hatred and pain
will be nothing but dust
at the end of the day

GeneralVery well Pin
benni19-Mar-04 1:31
benni19-Mar-04 1:31 
Generalautoscroll feature Pin
ledang5-Jan-04 22:29
ledang5-Jan-04 22:29 
Generalsource code Pin
VK14-Dec-03 23:28
professionalVK14-Dec-03 23:28 
Generalregion coordinates Pin
hsiaod11-Jun-03 22:39
hsiaod11-Jun-03 22:39 
GeneralRe: region coordinates Pin
DCUtility12-Jun-03 2:22
professionalDCUtility12-Jun-03 2:22 
GeneralRe: region coordinates Pin
hsiaod12-Jun-03 9:57
hsiaod12-Jun-03 9:57 
GeneralRe: region coordinates Pin
obni19913-Dec-06 7:00
obni19913-Dec-06 7:00 
GeneralWhats it all about if source code is not provided... Pin
Devpro AB9-Jun-03 16:21
Devpro AB9-Jun-03 16:21 
GeneralRe: Whats it all about if source code is not provided... Pin
DCUtility9-Jun-03 16:52
professionalDCUtility9-Jun-03 16:52 
GeneralNice work Pin
mgama19-Feb-03 8:20
mgama19-Feb-03 8:20 
GeneralGood job!!! Pin
jedyking22-Jan-03 6:53
jedyking22-Jan-03 6:53 
GeneralRe: Good job!!! Pin
DCUtility23-Jan-03 11:22
professionalDCUtility23-Jan-03 11:22 
Generalvery poor Pin
Ahmed Ismaiel Zakaria6-Dec-02 8:37
Ahmed Ismaiel Zakaria6-Dec-02 8:37 
GeneralRe: very poor Pin
MaTrIX2k26-Dec-02 9:21
MaTrIX2k26-Dec-02 9:21 
GeneralRe: very poor Pin
#realJSOP6-Dec-02 14:39
mve#realJSOP6-Dec-02 14:39 
QuestionWhy ??? Pin
hugo20106-Dec-02 7:04
hugo20106-Dec-02 7:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.