【问题标题】:Teamviewer breaks GetWindowRectTeamviewer 打破 GetWindowRect
【发布时间】:2013-11-24 09:35:28
【问题描述】:

我正在尝试通过进程名称抓取一个窗口并将其聚焦,然后对其进行截图。除非我打开 Teamviewer,否则它工作得很好(即使在使用 teamviewer 进行屏幕共享时,只是在 teamviewer 运行时)

当 teamviewer 运行时,窗口没有聚焦或被带到前台,它截取的矩形非常小 (33x21),通常为 1600x900。

这里是有问题的代码:

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

【问题讨论】:

    标签: c# user32


    【解决方案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 团队。


    测试: TeamViewer 9 版本。 9.0.27339,设置为无人值守访问;微软 Word 2007

    【讨论】:

      【解决方案2】:

      我也发现 teamViewer 破坏了 UI 自动化。禁用“显示此应用程序”功能可重新启用 UI 自动化工作。

      【讨论】:

        猜你喜欢
        • 2018-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-18
        相关资源
        最近更新 更多