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

IT Offers

Comments

  • buy cheap Phentermine online

    Posted by nushrerereuro on 05/24/2013 09:08am

    Buy Adipex Pills Phentermine Medication Cheap - Purchase Phentermine Online Cheap

    Reply
  • order generic Effexor Venlafaxine online no prescription

    Posted by Encantals on 05/16/2013 02:37pm

    This in turn can cause more sleeplessness and more anxiety. So un-learning the conditioning that cause the attacks very often is all it takes to cure the attacks. effexor migraine prevention. It is normal for us to have some slight anxiousness present in our daily lives. effexor 37.5 mg side effects. Order Venlafaxine Online Without Rx Cheap - link: [url=http://buyeffexoronlinepills.com#order-venlafaxine-pills]cheap effexor[/url] 2002 purchase effexor, Venlafaxine No Rx - where to buy effexor. long term effects of effexor. It is not a harmful condition, just very unnerving. efexor and alcohol

    Reply
  • order Wellbutrin 150mg online without a prescription

    Posted by PythittyJar on 05/11/2013 02:18am

    Buy Bupropion Drug Cheap Order Bupropion Without a Prescription - Generic Wellbutrin Drugs

    Reply
  • order ambien online

    Posted by eldeffimide on 05/09/2013 01:14am

    For example, public speaking is a source of anxiety for a lot of people. One thing menopause is great at, and that is bringing out our unresolved issues. ambien free trial coupon. Combine a few of these great ideas and see if you can help to cure your anxiety or panic attacks in a natural manner. took 3 10mg ambien. Zolpidem Online No Rx Cheap, More Help- [url=http://www.buyambienonlinepills.net#order-zolpidem-pills-cheap]ambien[/url] 2006 ambien without prescription- Order Ambien Online No Prescription, ambien buy online. pictures of generic ambien. This was to be the weekend our family was coming to visit us at the cabin we had fixed up back in the woods. taking 3 ambien pills

    Reply
  • buy cheap ambien online without a prescription

    Posted by dowecticore on 05/06/2013 02:01pm

    Ambien Without Rx Zolpidem Online Without Rx Cheap - Purchase Cheap Ambien Online No Prescription

    Reply
  • Nike Air Max+instagram, desire you contain the color to bear up on your feet!

    Posted by madytreathy on 04/22/2013 10:32am

    Recollect in 2008, if not earlier, when Nike launched ahead of the affluent shoe color projects, the slogan "Bound Your Colours", "Nike PhotoiD" blueprint, [url=http://markwarren.org.uk/goodbuy.cfm]nike free[/url] response has not been as avid as expected. Think, 2008 Canon IXUS 80 IS Digital file card arcade but contrariwise 8 million pixels, Nokia, the motorized phone market-place is the one administration, NikeiD was boost to color in the photos as a essence someone is concerned sneakers custom color, although gripping, but does provoke some. Instagram which communicate this passion game of and elemental, Nike PHOTOiD homeopathic upgrade customization services, recently [url=http://markwarren.org.uk/goodbuy.cfm]nike free run[/url] released a unique plan. That such iD can you appliance pictures as instagram account shoe color, little while make available Nike Air Max shoes and Nike Air Max 1, Nike Show Max 90 953 options. Interested in children's shoes, you [url=http://markwarren.org.uk/goodbuy.cfm]nike free run[/url] can always associate with's proper website photoid.Nike.com, in besides to browse other people's creative industry, or you can make an effort to upload your own instagram photo, physique your own Nike Mood Max.

    Reply
  • view site

    Posted by goodname144 on 04/18/2013 08:42pm

    Treatment takes time and commitment. All of these depression treatments take time, and sometimes it might feel overwhelming or frustratingly slow. That is normal. Recovery usually has its ups and downs., Related Site: http://ubajatuj.myhost21.com#63197 - Understanding the underlying cause of your depression may help you overcome the problem. For example, if you are depressed because of a dead end job, the best treatment might be finding a more satisfying career, not taking an antidepressant. If you are new to an area and feeling lonely and sad, finding new friends at work or through a hobby will probably give you more of a mood boost than going to therapy. In such cases, the depression is remedied by changing the situation., Recommended Site: http://ukahmoke.net78.net#78018 - Similarly, TORDIA showed a 54.8% improvement with CBT and drugs verses a 40.5% with drug therapy alone.

    Reply
  • Very Useful

    Posted by HanneSThEGreaT on 09/11/2007 04:32am

    Thanx!

    Reply
  • the problem to do like this

    Posted by nehzil on 05/28/2007 02:43am

    I try this method, but if i do this on timer, the captured window will not display normally, i don't know why and how to solve it? thanks

    Reply
  • Can I use 2 sub-routines Get24BitBmp & CaptureDesktop in my app?

    Posted by vinojkumar on 03/02/2007 01:22am

    Hi, Can I use the 2 sub-routines. This is not documented elsewhere so I used GetPixel to get the full screen. Now I want to use your 2 sub-routines altered to my needs. The project is NetMonitor and it is going to appear in Codeguru.com in another few weeks or so. I will give you commented credits in the sources of mine. Excellent work. My Link in codeguru is List Of Gurus->V->Vinoj Kumar and I have written many big articles. Thanks, Regards, Vinoj

    • Sure you can :-)

      Posted by golanshahar on 03/02/2007 09:43am

      Feel free to do it. Shahar

      Reply
    Reply
  • Loading, Please Wait ...

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

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds