Solved

Taking a screenshot on non visable window forms

Posted on 2007-11-14
4
323 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Disable extension 8 38
Add different cell to otherwise similiar row 4 39
Error handling in asp.net site 5 25
Create a datatable in vb.net dynamically 1 14
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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