C# Teamviewer中断GetWindowRect
我试图通过进程名抓取一个窗口并聚焦,然后截图。除非我打开了Teamviewer,否则它可以完美地工作(即使在使用Teamviewer进行屏幕共享时,也不能在Teamviewer运行时使用) 当teamviewer运行时,窗口没有聚焦或显示在前台,并且rect it屏幕截图非常小(33x21),通常为1600x900 以下是相关代码:C# Teamviewer中断GetWindowRect,c#,user32,C#,User32,我试图通过进程名抓取一个窗口并聚焦,然后截图。除非我打开了Teamviewer,否则它可以完美地工作(即使在使用Teamviewer进行屏幕共享时,也不能在Teamviewer运行时使用) 当teamviewer运行时,窗口没有聚焦或显示在前台,并且rect it屏幕截图非常小(33x21),通常为1600x900 以下是相关代码: proc = Process.GetProcessesByName(procName)[0]; SetForegroundWindo
proc = Process.GetProcessesByName(procName)[0];
SetForegroundWindow(proc.MainWindowHandle);
ShowWindow(proc.MainWindowHandle, SW_RESTORE);
Rect rect = new Rect();
GetWindowRect(proc.MainWindowHandle, ref rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics.FromImage(bmp).CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
这里是我得到这些函数的地方:
[DllImport("user32.dll")]
private static extern IntPtr ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect);
[DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hWnd);
我也遇到过类似的问题。在两台Windows7Pro计算机上,我注意到运行TeamViewer客户端时,以下代码停止工作
var wordProcess = Process.GetProcessesByName("winword")
.FirstOrDefault(process => process.MainWindowTitle.Contains(documentName));
设置断点并检查单个运行的WINWORD进程会发现process.MainWindowTitle属性在大多数情况下为空。而WinWord windows任务栏图标则清楚地显示标题
每次正确填充时,退出TeamViewer会将内容恢复到正常状态:Process.MainWindowTitle
我已向TeamViewer团队报告了该问题
通过以下方式进行测试:
TeamViewer 9版本。9.0.27339,设置为无人值守;我也发现teamViewer打破了UI自动化。禁用“显示此应用程序”功能将重新启用UI自动化