代码之家  ›  专栏  ›  技术社区  ›  Scott Ferguson

如何使用UIAutomation设置MDI子窗口的焦点

  •  1
  • Scott Ferguson  · 技术社区  · 15 年前

    我们需要自动化一个旧的遗留应用程序。 它使用MDI窗口。

    UIAutomation 我可以为每个MDI子窗口成功地获得适当的AutomationElement。

    下面是我尝试过的一些失败的示例代码:

            var desktop = AutomationElement.RootElement;
            var dolphin = desktop.FindFirst(TreeScope.Children,
                    new PropertyCondition(AutomationElement.NameProperty,
                        "Dolphin for Windows",
                        PropertyConditionFlags.IgnoreCase));
            dolphin.SetFocus();
    
            var workspace = dolphin.FindFirst(TreeScope.Children,
                    new PropertyCondition(AutomationElement.NameProperty,
                        "Workspace",
                        PropertyConditionFlags.None));
    
            var childWindow = workspace.FindFirst(TreeScope.Children, new
                    PropertyCondition(AutomationElement.NameProperty, "Sharp   "));
            childWindow.SetFocus();
    

    此代码的最后一行失败System.InvalidOperationException异常

    1 回复  |  直到 15 年前
        1
  •  1
  •   riffnl    15 年前