C++ Programming: Easy Screen Capture Using MFC/ATL

Introduction

CImage is a class shared by MFC and ATL. It provides support for easy manipulation of bitmaps and different graphic file formats (BMP, JPEG, GIF, and PNG).
This article presents an extension class having methods for screen images capture.

CScreenImage class

CScreenImage is derived from CImage, uses shared MFC/ATL classes and plain Windows API, so can be inserted in any MFC or ATL-based application.

CScreenImage::CaptureRect - captures an image from a given screen area;

CScreenImage::CaptureScreen - captures the entire screen image of the first monitor;

CScreenImage::CaptureWindow - captures the image of a given window.

CScreenImage::CaptureRect function implementation is shown below.
It uses the classic way of bit-blitting from the screen device context to a compatible memory device context.
Finally it attaches the bitmap handle to this object.
To be noticed the CAPTUREBLT flag used in BitBlt function call. This allows dealing with layered windows images.

Related links

About the Author

Ovidiu Cucu

Graduated at "Gh. Asachi" Technical University - Iasi, Romania.
Programming in C++ using Microsoft technologies since 1995.
Microsoft MVP awardee since 2006.
Moderator and article reviewer at Codeguru.com, the number one developer site.
Co-founder of Codexpert.ro, a website dedicated to Romanian C++ developers.

Downloads

Comments

console

Posted by mani
on 06/27/2014 09:23am

sry for my bad en
i am noob in c++ form
we need capture screen from game , i test your program and i think this work but i need it on console and if u can plz help me
i cant convert your program to console for microsoft visual studio c++
best regard

thanks to share, but i have a question ...

Posted by zhmx
on 09/02/2012 04:44am

firstly, i am sorry about my english.
this period of time, i am trapping in a question. when i use the function "BitBlt" to capture the image of video player, all the picture black it is.i know it use the technology of DirectX and the image show in overlay.
how can i capture the sure picture of video player in MFC?
thank you a lot!

Top White Papers and Webcasts

Live Event Date: March 19, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT
The 2015 Enterprise Mobile Application Survey asked 250 mobility professionals what their biggest mobile challenges are, how many employees they are equipping with mobile apps, and their methods for driving value with mobility.
Join Dan Woods, Editor and CTO of CITO Research, and Alan Murray, SVP of Products at Apperian, as they break down the results of this survey and discuss how enterprises are using mobile application management and private …

On-demand Event
Event Date: February 12, 2015
The evolution of systems engineering with the SysML modeling language has resulted in improved requirements specification, better architectural definition, and better hand-off to downstream engineering. Agile methods have proven successful in the software domain, but how can these methods be applied to systems engineering? Check out this webcast and join Bruce Powel Douglass, author of Real-Time Agility, as he discusses how agile methods have had a tremendous …