Solved

Taking a screenshot on non visable window forms

Posted on 2007-11-14
4
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20285101
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
ID: 20285223
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
ID: 20285618
Hmm, you will need some tricks, try with this:
http://www.codeproject.com/useritems/CapturingMinimizedWindow.asp
0
 
LVL 1

Author Comment

by:pyrokin
ID: 20286331
Thank you, that did it.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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