What is the best way to capture an application window in C #?

I developed a Windows Forms application to capture the windows of a video chat application (inbound, aka Remote and outbound, aka Local). For this I use unmanaged Windows API code. Here is the Capture code:

// Set Local Window localHandle = FindWindow(null, "local"); // Backup parent window for local prevLocalHandle = GetParent(localHandle); SetParent(localHandle, this.pBoxLocal.Handle); SetWindowLong(localHandle, GWL_STYLE, WS_VISIBLE + (WS_MAXIMIZE | WS_BORDER | WS_DISABLED)); MoveWindow(localHandle, 0, -TOP_BAR_HEIGHT, this.pBoxLocal.Width, this.pBoxLocal.Height + LOWER_BAR_HEIGHT, true); // Set Remote Window remoteHandle = FindWindow(null, "remote"); // Backup parent window for remote prevRemoteHandle = GetParent(remoteHandle); SetParent(remoteHandle, this.pBoxRemote.Handle); SetWindowLong(remoteHandle, GWL_STYLE, WS_VISIBLE + (WS_MAXIMIZE | WS_BORDER | WS_DISABLED)); MoveWindow(remoteHandle, 0, -TOP_BAR_HEIGHT, this.pBoxRemote.Width, this.pBoxRemote.Height + LOWER_BAR_HEIGHT, true); 

Here is the return code:

 // Return Windows SetParent(localHandle, prevLocalHandle); SetWindowLong(localHandle, GWL_STYLE, (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)); MoveWindow(localHandle, 0, 0, NORMAL_WIDTH, NORMAL_HEIGHT, true); SetParent(remoteHandle, prevRemoteHandle); SetWindowLong(remoteHandle, GWL_STYLE, (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)); MoveWindow(remoteHandle, 0, 0, NORMAL_WIDTH, NORMAL_HEIGHT, true); 

The goal is to move from this: alt text

For this:

alt text

And again!:)

I currently have two questions:

  • First of all, when I return the windows to the video chat application, sometimes a black rectangle remains in the upper left corner of the screen. It disappears when I update the area.

  • second and, most importantly, there are times when I capture the application window, I also fix its toolbars (although the measurements that I supply are only those that relate to the video area in the window).

Is there a better way to do this? Even if these are simply the best features! Remember: I want to get the video chat application windows and return them later.

Thanks in advance for any advice!

+4
source share
1 answer

Well, the first problem you pointed out is easy to fix. You can just call Refresh () when you return the windows. However, if you meant that there is a black rectangle on the main desktop, not a window, you can use http://msdn.microsoft.com/en-us/library/bb776346(VS.85).aspx , which Allow you to force desktop to update.

Regarding the second problem you are facing, since you were already messing with the Window Long method, why not just delete all borders, I believe that it might happen that the border may have a β€œThickFrame”, which you specify in the return methods but not capture methods, so it’s possible that you get toolbars and borders. You can verify this by calling GetWindowLong, storing that value and seeing what it is, so you can know exactly what to delete.

Although I'm not sure what the use of this application is. I believe that you can do this only because you are manipulating external screens.

0
source

All Articles