Click here to Skip to main content
11,935,031 members (51,094 online)
Click here to Skip to main content
Add your own
alternative version


91 bookmarked

Barry's Screen Capture

, 11 Jan 2003
Rate this:
Please Sign up or sign in to vote.
An article showing methods of screen capture

Sample Image - CapIT.jpg


This article demonstrates the methods of capturing different portions of the screen. You have the facility to then save the captured image to a file.


The idea for developing the article came to me when I had downloaded such a utility for capturing screen-shots for use in my articles like this one, on the Internet, but unfortunately the downloaded utility had too many nagging screens and obviously for a no-nags version I had to pay which I cannot afford. So the only way out was to develop one on my own, the MSDN sample WinCap could have served the purpose but the source was not available on the CD. So I started developing the article in MFC using the Win32 sample provided on the MSDN CD (WinCap). And also so as to be able to capture portions of the screen which I had done sometime ago in Visual Basic, since screen capture in Visual Basic is much easier and code for this is available in the Knowledge Base section of Visual Basic.


This article has the following features.

  • Capture the Desktop
  • Capture a window
  • Capture a client area
  • Capture a control (e.g. Button)

In addition it has the following, interesting but not so useful (in my view) features:

  • Track the X and Y coordinates of the captured image
  • Trace the color code of a specific point of the captured image

Option for color and position tracking are on the MainFrame window of the system and can only be used after capturing an image.

How to use the project

Download the project source, unzip the files to some folder, build the project, in case there are no error at build-time, execute the project, a Icon of a Camera will appear in the System Tray (bar at the bottom of the screen), Right-Click on the the Icon and a menu will pop-up, select the options from the menu.

Sample Image

Pop-up Menu

Option Task performed
Capture Desktop Captures a image of the System Desktop immediately
Capture Window Prompts to click on window to be captured
Capture Client Area Prompts to click on client area to capture
Capture Control Prompts to click on control to capture
Clear Image Clears captured image
Show Window Display the CapIT System Window
Close Closes the CapIT System

In addition to the pop-up menus the CapIT System has it own main menu which cap be displayed when you select "Show Window" from the pop-up menu.

How it works

When capturing window or client area or control, the system calls the function SetCapture() and waits for the user to click on some window on the Desktop which is to be captured. After clicking on the area to be captured, the system framework call the member function void CCapITView::OnCaptureChanged(CWnd *pWnd) which calls WindowCapture(HWND hwnd) which in turn carries out the job of capturing the image (till the menu are disabled). After completion of capture the system calls ReleaseCapture() to release SetCapture(). But in the case of capturing the Desktop SetCapture() is not called, but directly calls WindowCapture(HWND hwnd) passing to it GetDesktopWindow()->m_hWnd and the system proceeds with capturing the Desktop image immediately, since there is only one Desktop area and its HWND is known to the System.

Note :

The following member functions in the class CCapITView are borrowed from the MSDN sample WinCap. Could I have written them on my own, No Way.

  • HBITMAP CopyWindowToBitmap(CWnd* wnd , HWND hWnd, WORD fPrintArea)
  • HBITMAP CopyScreenToBitmap(LPRECT lpRect)
  • void DoSize(CWnd* wnd , HBITMAP ghBitmap)
  • void SetupScrollBars(CWnd* wnd , WORD cxBitmap, WORD cyBitmap)
  • void ReallyGetClientRect(CWnd* wnd , LPRECT lpRect)
  • WORD SaveDIB(HDIB hDib, LPSTR lpFileName)
  • WORD PaletteSize (VOID FAR * pv)
  • WORD DibNumColors (VOID FAR * pv)
  • HDIB ChangeBitmapFormat(HBITMAP hBitmap, WORD wBitCount, WORD dwCompression, HPALETTE hPal, HWND hwnd)
  • HPALETTE GetSystemPalette(HWND hwnd)
  • int PalEntriesOnDevice(HDC hDC)

Known problems

Color of the saved image under Windows 98 is not the same as of the captured image, but I think it is nearly the same in Windows 2000.

Points of interest

The project uses a CScrollView instead of CView because if the image being captured is bigger in size (e.g. Desktop) then in the Frame Window you may not be able to capture the entire image since a CView will capture as per the CView Client Area size.


  • Version 1


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Barretto VN
India India
Nothing to boast about

You may also be interested in...

Comments and Discussions

GeneralScrolling dont work Pin
cppoju23-Nov-07 13:18
membercppoju23-Nov-07 13:18 
GeneralAlt-Tab Pin
naykid319-Sep-06 8:41
membernaykid319-Sep-06 8:41 
GeneralRe: Alt-Tab Pin
Barretto VN19-Sep-06 22:38
memberBarretto VN19-Sep-06 22:38 
QuestionCan I get your email? Pin
Xueyan30-Jul-06 17:22
memberXueyan30-Jul-06 17:22 
QuestionHow to capture a transparent window Pin
nowlex6-Jan-06 12:58
membernowlex6-Jan-06 12:58 
AnswerRe: How to capture a transparent window [modified] Pin
Alexandru28-May-06 21:08
memberAlexandru28-May-06 21:08 
Generalcapture image without displaying application window Pin
jags_vc15-Feb-05 20:07
memberjags_vc15-Feb-05 20:07 
Can it posible that capturing image of any application window
without displying it.I mean that application is running in backgroud that mean it`s window is hide,Now can i capture that
window which is hide? if yes then how?Confused | :confused:
GeneralCapturing background Window Pin
tyounsi17-Jan-05 15:28
membertyounsi17-Jan-05 15:28 
GeneralGood Work Dude. Pin
ThatsAlok21-Jul-04 0:20
memberThatsAlok21-Jul-04 0:20 
GeneralI'm happy about this article Pin
Georgi Petrov26-May-04 2:42
memberGeorgi Petrov26-May-04 2:42 
Generalcapturing desktop Pin
nandiniarun4-Apr-04 22:47
membernandiniarun4-Apr-04 22:47 
GeneralRe: capturing desktop Pin
Barretto VN9-Apr-04 0:52
memberBarretto VN9-Apr-04 0:52 
GeneralRe: capturing desktop Pin
ThatsAlok21-Jul-04 0:17
memberThatsAlok21-Jul-04 0:17 
Generalmore information Pin
mahavirsinh vaghela3-Feb-04 1:15
membermahavirsinh vaghela3-Feb-04 1:15 
QuestionHow to capture a hidden window Pin
Sameers (theAngrycodeR )3-Jan-04 7:13
memberSameers (theAngrycodeR )3-Jan-04 7:13 
AnswerRe: How to capture a hidden window Pin
Anonymous9-Mar-04 11:29
sussAnonymous9-Mar-04 11:29 
GeneralRe: How to capture a hidden window Pin
Bob McCown22-Jul-04 11:49
memberBob McCown22-Jul-04 11:49 
GeneralRe: How to capture a hidden window Pin
GATJR10-Oct-06 7:40
memberGATJR10-Oct-06 7:40 
AnswerRe: How to capture a hidden window Pin
guangyen11-Mar-05 21:19
memberguangyen11-Mar-05 21:19 
GeneralRe: How to capture a hidden window Pin
Rajan Phatak31-Mar-05 20:58
memberRajan Phatak31-Mar-05 20:58 
GeneralRe: How to capture a hidden window Pin
faz793-Jun-05 2:00
memberfaz793-Jun-05 2:00 
GeneralRe: How to capture a hidden window Pin
kajok3-Oct-06 7:27
memberkajok3-Oct-06 7:27 
GeneralEverytime I pressed Capture desktop, it eats 4 MB of memory.. Pin
Mr. Jigar Mehta2-Jan-04 3:47
memberMr. Jigar Mehta2-Jan-04 3:47 
QuestionHow to Capture Screen with DirectX ? Pin
hiver6-Dec-03 4:27
memberhiver6-Dec-03 4:27 
AnswerRe: How to Capture Screen with DirectX ? Pin
Kovari Attila15-Feb-04 22:42
memberKovari Attila15-Feb-04 22:42 
GeneralRe: How to Capture Screen with DirectX ? Pin
m_idris8-Jun-04 20:17
memberm_idris8-Jun-04 20:17 
GeneralWill try the code, save me a lot of time. Pin
w0705310-Jul-03 12:47
memberw0705310-Jul-03 12:47 
GeneralRe: Will try the code, save me a lot of time. Pin
Mr. Jigar Mehta5-Jan-04 0:02
memberMr. Jigar Mehta5-Jan-04 0:02 
GeneralRe: Will try the code, save me a lot of time. Pin
w070536-Jan-04 9:31
memberw070536-Jan-04 9:31 
GeneralSaving to JPG Pin
bob_brown_200025-Apr-03 19:52
memberbob_brown_200025-Apr-03 19:52 
GeneralRe: Saving to JPG Pin
ThatsAlok21-Jul-04 0:45
memberThatsAlok21-Jul-04 0:45 
GeneralRe: Saving to JPG Pin
Barretto VN28-Jul-04 2:07
memberBarretto VN28-Jul-04 2:07 
GeneralRe: Saving to JPG Pin
ThatsAlok28-Jul-04 4:19
memberThatsAlok28-Jul-04 4:19 
GeneralRe: Saving to JPG Pin
Barretto VN2-Aug-04 2:17
memberBarretto VN2-Aug-04 2:17 
GeneralGood Program. Pin
Seungju Choi13-Jan-03 20:44
memberSeungju Choi13-Jan-03 20:44 
GeneralRe: Good Program. Pin
eegiboo12-May-03 17:11
membereegiboo12-May-03 17:11 
GeneralRe: Good Program. Pin
Anonymous12-Apr-05 20:08
sussAnonymous12-Apr-05 20:08 
Generalgood article, any equivalent in c# and vs7 Pin
elwolv12-Jan-03 6:16
memberelwolv12-Jan-03 6:16 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 12 Jan 2003
Article Copyright 2003 by Barretto VN
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid