2

I'm looking for a way to get a picture of the Main Window of a process without getting a screenshot of the whole desktop. I want to be able to get a picture of minimized windows and covered windows. Ideally I'd like to get this image as a Bitmap object for later manipulation.

I can already get the hwnd for the Main Window using System.Diagnostics.Process, where can I use that hwnd to get the image of the window? I do expect to need to use the WinAPI, I just don't know where.

Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
  • 1
    This might be helpful: http://stackoverflow.com/questions/1163761/c-capture-screenshot-of-active-window – Martin Buberl Jan 21 '11 at 00:45
  • Exact duplicate http://stackoverflow.com/questions/1163761/c-capture-screenshot-of-active-window. Second answer tells how to do it without screenshot – Shekhar_Pro Jan 21 '11 at 03:08
  • Shekhar_Pro: g.CopyFromScreen(...) is fundamentally a screenshot. It is not a duplicate and it does not answer my question. – Corey Ogburn Jan 22 '11 at 01:50

1 Answers1

3

Create a memory DC. Send the handle of that memory DC to the hWnd of the main window to a PRINT message to the window.

  • http://www.pinvoke.net
    Great way to explore WINAPI and figure out how to call the different methods.
  • http://www.codeguru.com/Csharp/Csharp/cs_graphics/drawing/article.php/c6137
    This article shows how to create Memory DCs using pinvoke.
Lee Louviere
  • 5,162
  • 30
  • 54