Home > Mobile >  Take a screenshot behind window in C# WinForm
Take a screenshot behind window in C# WinForm

Time:09-17

I'm working on an app in c# windows forms, I have a form called Form1 with a button, and after click this button the idea is to take a screenshoot of everything behind it except the Form1 itself (without minimizing Form1).

Any idea or suggestion?

Thank you!

CodePudding user response:

you can use hard code. Actually light shot and other tools working such as. When you click to screenshot button you may close the form window after the event and reopen it. it is the basic way of solution... Please check this way: How can i capture the screen without the Form?

CodePudding user response:

If you want a solution without hiding, moving, minimizing etc., you need the following approach:

  1. EnumWindows() to iterate all windows. This will give you the windows top to bottom.
  2. Don't forget to exclude your own window
  3. Exclude windows that are invisible. Check out GetWindowLongPtr with GWL_STYLE and compare against WS_VISIBLE
  4. GetWindowRect() to get their size
  5. PrintWindow() to get a bitmap of the window, no matter whether it's in the background
  6. Create a bitmap with the size of the VirtualScreen
  7. Paint the windows in reverse order (bottom to top) using DrawImage()

I found that this is quite fast (514 ms on a 2560x1440 screen with 20 visible windows to draw).

Limitations:

  • since it sends a WM_PRINT message to the application, you can not capture applications that are "not responding"
  • For me, Firefox does not render well. It's missing page contents.
  • For me, control panel content appears black, although it's there when getting a screenshot of the whole screen.
  • Related