的TeamViewer打破GetWindowRect(Teamviewer breaks GetWi

2019-10-18 23:57发布

我试图通过进程名抢窗口和重点,然后取它的截图。 它完美的作品,除非我有开放的TeamViewer(甚至没有在使用的TeamViewer到屏幕分享,就在TeamViewer是运行)

当TeamViewer是运行窗口不集中或推到前台,并RECT这截图是非常小(33x21),而正常情况下这将是1600×900。

这是有问题的代码:

        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);

Answer 1:

我也遇到了类似的问题。 在两个Windows 7 Pro电脑我注意到,与客户端的TeamViewer运行下面的代码停止工作。

var wordProcess = Process.GetProcessesByName("winword")
    .FirstOrDefault(process => process.MainWindowTitle.Contains(documentName));

设置断点和检查单运行WINWORD过程揭示Process.MainWindowTitle属性是空白的大部分时间。 虽然WINWORD Windows任务栏上的图标清楚地显示标题。

退出的TeamViewer恢复一切恢复正常:Process.MainWindowTitle每次变成正确填充。

我已报告的问题到的TeamViewer队。


测试了:9的TeamViewer版本。 9.0.27339,无人值守访问设置; MS Word 2007中



Answer 2:

我也发现,休息的TeamViewer UI自动化。 禁用“当前这个应用程序”功能重新启用UI自动化工作。



文章来源: Teamviewer breaks GetWindowRect
标签: c# user32