Capturing Windows Regardless of Their Z-Order

Introduction

This article demonstrates how to capture top-level windows with the WS_VISIBLE style, regardless of their z-order.

Functionality Included

  • Capture all the screen content to a BMP file.
  • Capture the foreground window content to a BMP file.
  • Capture the covered window content to a BMP file.

All functionality is implemented inside the CaptureEx class and, in addition to capturing screen content, one can find other useful functionality of the class, such as:

  • Creating (saving) a BMP file from raw bits.
  • Converting any input HBITMAP into 24-bit raw bits.
  • Stretching (zoom in/out) BMP raw bits to a given window handle.

About the Project

Capturing window content can be done easily by using the ::BitBlt(..) from the screen DC; however, this kind of implementation forces you to make sure that the window you want to capture is on top of the screen. In this project, to capture all the screen (Desktop), this technique is useful. Because it's not good for capturing covered windows, I capture windows with the ::PrintWindow(..) API.

The project is a MFC-dialog based application, built with VC6. However, as mentioned above, all the implementations are inside the CaptureEx class, so actually MFC is being used just as a wrapper for the GUI; the CaptureEx functionality is implemented with the Win32 API. In that way, Win32 applications can also benefit from the class.

How It Works

When the application starts running, it uses ::EnumWindows(..) to build a list of all top/visible windows; each valid window for capturing is added to the list. Clicking "Refresh Windows List" will update the windows list.

Once you have all the windows in the list, you can select a window from the list (using the mouse/arrow keys); each selected window will be captured and displayed on the dialog. The capture is made without changing the window's Z-order.

You can change the preview slider to zoom in/out the captured window image; clicking "Show actual size" will display the captured window image at its real size.

To save a particular captured window to a BMP file, press the "Save window to Bmp" button.

All captured windows will be saved at their real size, no matter how the preview is set.

Note: Capturing minimized windows (Iconic) will only generate the caption image of the window. Here is a sample of Iconic window capture:

The CaptureEx Class

Useful functions of the CaptureEx class are shown in this code snippet:

class CaptureEx
{
   :
   public:
   void SaveBmpToFile(LPTSTR szFileName, int W,int H,
                      int Bpp, int* lpBits);
   void Get24BitBmp ( const int &nWidth,const int &nHeight,
                      const HBITMAP &hBitmap, BYTE *lpDesBits);
   void CaptureDesktop (double fPreviewRatio,
                        LPTSTR lpszFileName,
                        BOOL bSaveToFile);
   void StretchDIBitsToHwnd( HWND hWnd, double fRatio,
                             int Width, int Height,int Bpp,
                             BYTE *lpBits);
   BOOL CaptureWindow( HWND hWndSrc, double fPreviewRatio,
                       LPTSTR lpszFileName,BOOL bSaveToFile);
   :
   :
};

Known Issue

During the development of the application, I ran into a problem with capturing IE windows; sometimes, part of the image goes black. I assume it's due to the way IE windows repaint themselves. At the moment, the solution I came up with is to capture each window a couple of times and get the correct image by using image filtering.



Downloads

Comments

  • De quelle couleur est la prochaine Katy Perry?

    Posted by wgggpj700 on 07/16/2013 04:44am

    GHD Styler Hair utilise des plaques en céramique chauffées à la fois les cheveux raides et boucle. Un bon entretien permettra d'assurer votre styler GHD dure aussi longtemps que possible. Nettoyage des résidus de produits coiffants de style devrait faire partie de l'entretien régulier. Il gardera le styler est à son meilleur. Vous pouvez facilement nettoyer votre styler GHD sans causer de défrisants damage.Ceramic sont préférés pour le salon et le style de la maison. [url=http://ghdpascherfer.hpage.com/]lisseur ghd styler[/url] Comme de plus en plus de gens dans le monde veulent Rett cheveux, GHD pinces de défrisage maintenant été activés difficiles populaires de siste ans. Ces cheveux droite n'est certainement pas un concept clic helpf, et il était bien difficile dans les années 60 - et 70-siècle à la grande canne de boucles dans la paille dans åttiårene. Mais la beste partie audiovisuelle ces GHD skjønnhetsprodukter est qu'ils peuvent être utilisés pour coiffer les cheveux à peu près tout une forme autre, que ce soit bølgete poker, à tort ou courbe. Et qu'est-ce que vous choisissez de faire, vous êtes sûr y faire beaucoup on se tourne la tête. [url=http://ghdpascherferfr.webgarden.com/]ghd lisseur prix[/url] Il a toutes les fonctionnalités dont vous avez besoin et offre un bel éclat rempli et les cheveux doux et soyeux avec un finish.Tangen avoir nano-revêtement qui protège les cheveux contre les dommages de la chaleur et des manches longues et minces disques minces (120 x 24 mm), qui est également verrouillable . Il est équipé de la fonction ionique, une fonction qui émet des ions négatifs qui empêchent la formation d'électricité statique pendant que vous section. Fonction Ionic ferme la tige du cheveu et offre une lisse les cheveux avec plus d'éclat. ! Avec une température maximale de 230 degrés s'adapte à tous les types de cheveux et longueurs et réchauffe la température de travail en seulement 20 secondes D'autre part, il y aura un nombre égal de femmes qui ont blessé des anneaux et des produits de beauté ces GHD peut atteindre n'importe quel look; afin femme aux cheveux bouclés peut être heureux avec elle dirigée cheveux raides femme de cheveux raides peuvent prendre du plaisir dans ses cheveux bouclés.

    Reply
  • purchase Zyprexa 2.5mg online without a prescription

    Posted by BuyZyprexa41 on 07/09/2013 11:04am

    You can bring back your self confidence to do your daily activities. order cheap Zyprexa online purchase cheap Zyprexa online I had my first anxiety panic attack when I was 28, and spent months trying to [url=http://www.zyprexabuyonline.com/#51-purchase-zyprexa-generic]purchase Zyprexa online no prescription[/url] Its aroma has a powerfully grounding and reassuring effect that may be relied upon to relieve stress, anxiety or panic.

    Reply
  • Order Zyprexa Online Without Rx Cheap

    Posted by generic-zyprexa on 07/07/2013 08:55am

    zyprexa 5 mg bula, explained here: Purchase Cheap Zyprexa Online Pharmacy - zyprexa zydis lawsuit, Buy Cheap Zyprexa Medication

    Reply
  • Zyprexa Online Without Prescription Cheap

    Posted by Kristen209 on 07/02/2013 03:03pm

    Buy Cheap Olanzapine Medication Buy Olanzapine Online No Rx Cheap - zyprexa zydis medication

    Reply
  • order Escitalopram online

    Posted by Traistasteway on 07/01/2013 02:00am

    e-newsletter keeps you up to date on a wide variety of health topics. When suffering from Dysthymia, people are in low mood practically all the day. It can last up to two years and people have moods most days. lexapro 5mg safe. Why are you feeling depressed? What is bothering you? What needs to change to help you to feel better? Is it something in your present, or are there unresolved issues in your past or in your childhood that you still need to deal with and which are affecting your life and your relationships? dealing with lexapro insomnia. Escitalopram Price - This Site: [url=http://www.lexaprobuyonlinepills.com#order-lexapro-online-cheap]buy generic lexapro online[/url] 2002 buy generic lexapro online- Order Cheap Escitalopram Without a Prescription, lexapro generic. can lexapro help back pain. ©2005-2012 WebMD, LLC. All rights reserved. lexapro dosage amount

    Reply
  • Purchase Fluoxetine Without Prescription

    Posted by Polina273 on 06/28/2013 11:02am

    Prozac Online No Rx Cheap Order Cheap Fluoxetine Price - prozac dosage strength

    Reply
  • buy Lexapro online no prescription

    Posted by RawweRasmanty on 06/27/2013 07:34pm

    Insomnia, fatigue, headache, stomachache, dizziness purchase Lexapro online buy generic Lexapro Escitalopram online without a prescription. Tricyclic antidepressants have more side effects than SSRIs and are usually reserved for the treatment of inpatients, for whom the tricyclic antidepressant amitriptyline, in particular, appears to be more effective. [url=http://www.lexaprobuyonlinepills.com/#928167-order-lexapro-pills]buy Lexapro 10mg online no prescription[/url] Katon W, Von Korff M, Lin E, et al. Stepped collaborative care for primary care patients with persistent symptoms of depression: a randomized trial. Arch Gen Psychiatry 1999; 56:1109.

    Reply
  • purchase generic Zyprexa Olanzapine online

    Posted by ZyprexaOnline79 on 06/26/2013 07:56am

    lilly zyprexa patent Buy Zyprexa Online bad side effects of zyprexa [url=http://www.zyprexabuyonline.com/#52-cheap-zyprexa-drug] Buy Zyprexa No Prescription Cheap [/url] low dose zyprexa for sleep Olanzapine Online Medication Cheap zyprexa 5 mg forum

    Reply
  • order Prozac 40mg online

    Posted by BuyProzac59 on 06/25/2013 08:50am

    prozac for general anxiety disorder Fluoxetine Pills Cheap side effects quitting prozac [url=http://www.prozacbuyonline.com/#37-purchase-cheap-prozac-anxiety-treatment] Cheap Fluoxetine Online Without Prescription [/url] prozac lexapro comparison Prozac Without a Prescription prozac bipolar manic

    Reply
  • buy Ultram online without a prescription

    Posted by higImmimi on 06/24/2013 06:50pm

    Purchase Ultram Online Without Prescription Buy Tramadol No Prescription - Order Ultram Online No Rx Cheap

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Not long ago, security was viewed as one of the biggest obstacles to widespread adoption of cloud-based deployments for enterprise software solutions. However, the combination of advancing technology and an increasing variety of threats that companies must guard against is rapidly turning the tide. Cloud vendors typically offer a much higher level of data center and virtual system security than most organizations can or will build out on their own. Read this white paper to learn the five ways that cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds