将新窗口添加到桌面时是否触发任何事件 [英] Is there any event triggered when a new window is added to the desktop

查看:88
本文介绍了将新窗口添加到桌面时是否触发任何事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在桌面上出现/出现新窗口时是否触发任何事件.我愿意使用COM,WMI,WinApis,UIAutomation或任何其他方法,但是选择的语言是C#.

I want to know whether there is any event triggered when a new window appears/comes on the desktop. I am open to using COM,WMI,WinApis, UIAutomation or any other method but the language of choice is C#.

实际要求: 一个进程有1个主窗口和许多其他窗口.其中一个窗口的类名称是X,(我是通过pinvoke获得此信息的).现在,在此过程中每当有一些通知时,都会弹出此窗口一些时间.我不想显示此窗口.我没有对该进程的代码访问权限,因此我可以禁用该窗口.因此,有什么办法可以让我获得一个事件或任何其他机制来跟踪桌面,并且何时只要有/即将有一个类名X的窗口来隐藏它即可.

The actual requirement: A process has 1 main window and many other windows. The class name of one of the windows is, say, X, (i got this info using pinvoke). Now this window pops up some times whenever there is some notification in the process. I do not want to show this window. I do not have code access to that process so that i can disable that window. So is there any way that i can get an event or any other mechanism which keeps track of the desktop and anytime a window with classname X comes/about to come it hides it.

请告诉我我是否不清楚这个问题. 谢谢

Do tell if i am not clear with the question. Thanks

Simon的回答确实很好.我尝试了一下,并且能够获得除通知/举报窗口(例如lync的im toast通知或Outlook New Mail通知的窗口)以外的所有窗口的通知.我尝试使用Automation Element和Windows Pattern的不同元素,但仍然无法获得这些...任何想法如何获得这些...您可以阅读Simon答案中的注释以获取更多上下文/详细信息.再次感谢西蒙(Simon)介绍了UIAUtomation的强大功能 ...热爱它!

推荐答案

正如Damien在他的评论中所说,您可以在C#示例控制台应用程序中使用UI自动化,如下所示:

As Damien said in his comment, you can use UI automation, like this in a C# sample console app:

class Program
{
    static void Main(string[] args)
    {
        Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Subtree, (sender, e) =>
            {
                AutomationElement src = sender as AutomationElement;
                if (src != null)
                {
                    Console.WriteLine("Class : " + src.Current.ClassName);
                    Console.WriteLine("Title : " + src.Current.Name);
                    Console.WriteLine("Handle: " + src.Current.NativeWindowHandle);
                }
            });

        Console.WriteLine("Press any key to quit...");
        Console.ReadKey(true);
    }
}

这篇关于将新窗口添加到桌面时是否触发任何事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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