UI自动化切换窗口 [英] UI Automation switch window

查看:61
本文介绍了UI自动化切换窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到 setforegroundwindow 可能非常不稳定 - 无论您如何操作.

I've noticed that setforegroundwindow can be very flaky - no matter how you do it.

我注意到在可能的情况下使用 UIAutomation 似乎可以改善情况.

I've noticed that using UIAutomation, where possible, seems to improve things.

例如:

获取 WindowPattern 并使用以下内容:

Getting the WindowPattern and using something like:

windowPattern.SetWindowVisualState( WindowVisualState.Normal );

windowPattern.SetWindowVisualState( WindowVisualState.Maximized );

现在我的问题是:

我怎么知道我应该让它最大化还是正常.任务管理器和龙自然说话似乎都知道该怎么做.如果之前最大化,然后最小化,我想在切换到它时最大化窗口.如果之前没有最大化,我想把它设为正常".

How do I know whether I should make it maximized or normal. The task manager, and dragon naturally speaking both seem to know how to do this. If it was previous maximized, and then minimized, I'd like to maximize the window when I switch to it. If it was previously not maximized, I'd like to make it "Normal".

有什么想法吗?

推荐答案

SetFocus for AutomationElement 无效.

SetFocus for AutomationElement didn't work.

来自以下问题:获取另一个进程的窗口状态

我发现 GetPlacement api 提供了我需要的东西:

I found that the GetPlacement api gave me what I needed:

     if ( (windowplacement.flags & WPF_RESTORETOMAXIMIZED) > 0 )
     {
        windowPattern.SetWindowVisualState( WindowVisualState.Maximized );
     }
     else
     {
        windowPattern.SetWindowVisualState( WindowVisualState.Normal );
     }

这样窗口在最大化时会恢复到最大化,如果没有最大化则恢复正常.

With this the window will restore to maximized if it was maximized and restore to normal if it was not maximized.

这篇关于UI自动化切换窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆