从窗口句柄.NET类的名字 [英] .net class name from a window handle

查看:175
本文介绍了从窗口句柄.NET类的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作是监视什么是Windows机器上运行的应用程序。它将被用来发出警报,如果在自动处理某些对话框弹出。我使用Windows的API来获取现有的窗口类名,工作正常。但是,如果这些都是.NET应用程序,然后而不是.NET类的名字,我得到的东西像'WindowsForms10.Window.8.app.0.39cfeeb,而更糟糕的是,类名不执行之间不变。

I'm working on an application that monitors what's running on a windows machine. It will be used to raise alarms if certain dialogs pop up during automated processes. I'm using the windows API to get the class name of existing windows, which works fine. However, if these are .NET applications, then rather than the .NET class name, I get something like 'WindowsForms10.Window.8.app.0.39cfeeb', and to make matters worse, the class name is not constant between executions.

有没有办法让当时只有psented与Windows $ P $处理.NET类的名字?

Is there a way to get the .NET class name when only presented with a windows handle?

推荐答案

是的,这可不行。在桌面会话的每个唯一窗口必须有唯一的视窗类名称,()传递给RegisterClassEx()WINAPI函数和用于CreateWindowEx函数字符串。的WinForms自动生成的名称,以便它的负担,以确保它生成的名称不带窗户的其他进程和应用程序域的名称发生冲突。这就是为什么你看到这些比扎罗名字,最重要的部分是最后一位,39cfeeb在你的榜样,通过AppDomain.GetHash code返回的值()。你不能从外部过程检索散列code。

Yes, this can't work. Every unique window in a desktop session must have a unique Windows "class name", the string passed to the RegisterClassEx() winapi function and used in CreateWindowEx(). Winforms auto-generates those names so it has the burden to ensure that the names it generates don't collide with names of windows in other processes and appdomains. Which is why you see these bizarro names, the most important part is the last bit, 39cfeeb in your example, the value returned by AppDomain.GetHashCode(). You cannot retrieve that hash code from an external process.

您将需要不依赖于容易获得类名完全不同的方法。看管理谍code ,它支持使用反射外部的WinForms的过程。隔离它采用这样你就可以使用这个自己在自己的code中的DLL注入code技术利用了一些工作。

You'll need a fundamentally different approach that doesn't rely on the easily obtainable class name. Look at the Managed Spy code, it supports using Reflection on an external Winforms process. Isolating the DLL injection code technique it uses so you can use this yourself in your own code takes some work.

也只有这样,你永远得到的.NET类的名字在这个过程中,你的东西,否则永远不会真正在乎使用UI自动化的时候。

Also the only way you'll ever get the .NET class name out of the process, something you otherwise never really care about when using UI automation.

这篇关于从窗口句柄.NET类的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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