Solved

Taking a screenshot on non visable window forms

Posted on 2007-11-14
4
322 Views
Last Modified: 2010-04-15
Hello,

   I need to hide a windows form, we will say calc.exe for this example, and then take a screenshot of it. Does anyone know of a way to do this?
0
Comment
Question by:pyrokin
  • 2
  • 2
4 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
Have a look to this article about capturing':
http://www.codeproject.com/csharp/screen_capturing.asp

there you will find the following method:
public static Bitmap GetWindowCaptureAsBitmap(int handle)
{
    IntPtr hWnd = new IntPtr(handle);
     Win32.Rect rc = new Win32.Rect();
     if (!Win32.GetWindowRect(hWnd, ref rc))
          return null;
 
    // create a bitmap from the visible clipping bounds of
    //the graphics object from the window
     Bitmap bitmap = new Bitmap(rc.Width, rc.Height);
 
    // create a graphics object from the bitmap
     Graphics gfxBitmap = Graphics.FromImage(bitmap);
 
    // get a device context for the bitmap
     IntPtr hdcBitmap = gfxBitmap.GetHdc();
 
    // get a device context for the window
     IntPtr hdcWindow = Win32.GetWindowDC(hWnd);
   
    // bitblt the window to the bitmap
     Win32.BitBlt(hdcBitmap, 0, 0, rc.Width, rc.Height,
        hdcWindow, 0, 0, (int)Win32.TernaryRasterOperations.SRCCOPY);
     
    // release the bitmap's device context
     gfxBitmap.ReleaseHdc(hdcBitmap);    
 
    Win32.ReleaseDC(hWnd, hdcWindow);
 
    // dispose of the bitmap's graphics object
     gfxBitmap.Dispose();  
 
    // return the bitmap of the window
     return bitmap;  
}
0
 
LVL 1

Author Comment

by:pyrokin
Comment Utility
jaime_olivares,

   From my understanding this will only work with visible windows, when I attempt I get the desktop in the size of the target window.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
Comment Utility
Hmm, you will need some tricks, try with this:
http://www.codeproject.com/useritems/CapturingMinimizedWindow.asp
0
 
LVL 1

Author Comment

by:pyrokin
Comment Utility
Thank you, that did it.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now