我開發了一個簡單的Windows窗體應用程序來捕獲視頻聊天應用程序(入站,又名遠程和出站,又名本地)的窗口。 我爲此使用了非託管Windows API代碼。這裏是捕捉代碼:在C#中捕獲應用程序窗口的最佳方式是什麼?
// 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);
這裏是返回代碼:
// 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);
的目標是從這個去:
要這樣:
然後回來又來了! :)
目前有兩個問題與我的處事方式:
首先,當我返回窗口視頻聊天應用,ocasionally一個黑色的矩形留在我頂屏幕左上角。刷新區域時消失。我也捕獲了它的工具欄(雖然我提供的測量結果只是關於窗口視頻區域的測量結果),但是有時候我捕捉應用程序的窗口。
有沒有更好的方法來做到這一點?即使它只是更好的功能!請記住:我想獲取視頻聊天應用程序的窗口,然後返回。
在此先感謝您的任何提示!