Taking a screenshot on non visable window forms


   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?
Who is Participating?
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
Hmm, you will need some tricks, try with this:
Jaime OlivaresSoftware ArchitectCommented:
Have a look to this article about capturing':

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
    Win32.ReleaseDC(hWnd, hdcWindow);
    // dispose of the bitmap's graphics object
    // return the bitmap of the window
     return bitmap;  
pyrokinAuthor Commented:

   From my understanding this will only work with visible windows, when I attempt I get the desktop in the size of the target window.
pyrokinAuthor Commented:
Thank you, that did it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.