Snapshot of any window in foreground? Similar to Task Switcher
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1

Thread: Snapshot of any window in foreground? Similar to Task Switcher

Hybrid View

  1. #1
    Join Date
    Apr 2011

    Snapshot of any window in foreground? Similar to Task Switcher

    Title is self explainatory.
    Here is the code:
            public Bitmap CaptureWindow(IntPtr hWnd)
                Rectangle rctForm = Rectangle.Empty;
                IntPtr test = GetWindowDC(hWnd);
                Graphics grfx = Graphics.FromHdc(test);
                using (grfx)
                    RectangleF test2 = grfx.VisibleClipBounds;
                    rctForm = Rectangle.Round(grfx.VisibleClipBounds);
                Bitmap pImage = new Bitmap(rctForm.Width, rctForm.Height);
                Graphics graphics = Graphics.FromImage(pImage);
                IntPtr hDC = graphics.GetHdc();
                //paint control onto graphics using provided options        
                    PrintWindow(hWnd, hDC, (uint)0);
                return pImage;
    Now... It works for most of the windows but not all. Example:
    Non working: Its a Delphi program but i guess it doesnt matter. Same happens to few others.

    The function is called in on Load event of my Form containing PictureBox
     pictureBox1.Image = CaptureWindow(okienko);
    'okienko' is a handle to that window.

    I already tested out few solutions using gdi32.dll and user32.dll functions but without luck.

    1.What i have already discovered is different property of 'Graphics grfx = Graphics.FromHdc(test);'

    2.Working thumbnails has "IsVisibleClipEmpty" property set to false, while blank ones are true values.

    3.Function returns in this line each time it crashes:
     rctForm = Rectangle.Round(grfx.VisibleClipBounds);
    Im also curious how did they manage to do it in win7(alt-tab task switcher)? Do you have any clues mighty gurus? What could possibly set the IsVisibleClipEmpty property to true if i can get the handle to the window and see the content with my own eyes? Why is it blind for some windows and then miraculously cured the other second on?
    Last edited by qwqwqw12; October 3rd, 2011 at 08:39 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Azure Activities Information Page

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


HTML5 Development Center