Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - How to screen-capture, except for some windows

Situation: I have a software that performs screen sharing over the Internet, where one user acts as a presenter, and other users act as viewers/attendees.

Besides the presentation windows, the presenter also has a set of NON-SHARING-WINDOWS that appear on the screen (a button bar for start sharing/stop sharing/etc., a Skype window etc.).

The presenter can configure from the setup of the screen sharing software to make these NON-SHARING-WINDOWS invisible (i.e. they will not appear in the screen sharing that is being sent to the attendees, but the window content behind them will appear in the screenshot).

The screenshots are sent at approximately 10 frames-per-second, or faster.

Question: how can I programmatically capture the screen, except for these NON-SHARING-WINDOWS windows?

Notes:

  • Because of the higher frames-per-second value, I cannot minimize/maximize/set alpha for these windows, because then the windows will flicker. The application is written in Win32 C++.
  • I would use layered windows, but because of the Windows 7 Desktop Composition feature, this is not usable out-of-the-box (and in Windows 8, you cannot use DwmEnableComposition anymore to temporarily and programmatically disable composition)
  • I could use the layered window approach for Windows XP/2000/7 etc., and a different approach for Windows 8 (if there is one), though I would prefer a single process that works on all systems
  • I could also try to "compose" the screenshots by capturing individual images (of the desktop, the windows that need to be captured) and using their z-index to create the final image, but because of the required frames-per-second value, this process would be too slow.
like image 291
Sucata Mihnea Avatar asked May 04 '12 08:05

Sucata Mihnea


People also ask

How do I capture only part of a screen in Windows?

Press Ctrl + PrtScn keys. The entire screen changes to gray including the open menu. Select Mode, or in earlier versions of Windows, select the arrow next to the New button. Select the kind of snip you want, and then select the area of the screen capture that you want to capture.

Which is the tool to be used to capture certain screen area?

Snipping tool is a program which is part of Windows Vista and above versions. Snipping Tool allows you to take a screenshot of your screen. It can be delayed for a few seconds while capturing the screen in case of hover. It allows the user to capture the whole screen or user-specified area in a rectangular form.

Which Windows application allows you to capture all or part of the screen?

Snipping Tool helps you to take a screenshot of your screen. It enables users to capture the whole screen or selected area in a rectangular form.

How do you take a screenshot of a focus?

1. Hold down the alt key and press the Print Screen button on your keyboard. This will capture only the in-focus/active window (the window 'on top'. This places the image on the clipboard, ready to be pasted into an application.


1 Answers

In windows even the desktop is considered a window and has its own HWND. It seems however, not easily possible to only copy the "wallpaper" on its own.

So i basically see two ways to do that. 1. Copy the entire desktop e.g. BitBlt(GetWindowDC(GetDesktopWindow()),...)

OR

  1. Use GetWindow and traverse the window list in backward direction starting from the Desktop-Window whose HWND you just can determine with GetDesktopWindow(), Like this:

    // paint on a black DC hwnd=GetDesktopWindow() while (hwnd = GetWindow(hwnd, GW_HWNDPREV)) { // is this window not shared? continue // else bitblt it into our dc }

Hope i gave some inspiration :-) If someone knows a way how to copy ONLY the desktop without its child windows please let me know.

like image 104
Felix M. Avatar answered Oct 24 '22 15:10

Felix M.