简体   繁体   English

WPF无需修改应用程序即可在鼠标下找到控件

[英]WPF find control under mouse without modifying the application

I'm creating a log system ('outside' the application) that logs all the click on the application. 我正在创建一个日志系统(在应用程序外部),用于记录该应用程序上的所有点击。 I have setup a PreFilterMessage function wich detects a click from the mouse, but I can't find the control/element that was clicked. 我已经设置了一个PreFilterMessage函数,该函数可以检测到来自鼠标的单击,但是找不到被单击的控件/元素。

I've tried with Mouse.DirectlyOver but the element is always null . 我已经尝试过使用Mouse.DirectlyOver但是该元素始终为null I've tried also with VisualTreeHelper.HitTest but I don't have a Visual to make the search from. 我也尝试过使用VisualTreeHelper.HitTest但是我没有Visual可以进行搜索。

I don't have access to the inside of the application: only to the Main method (with the Application.Run(new MainForm()); and my Application.AddMessageFilter(new Logger()); ). 我无权访问应用程序的内部:只能访问Main方法(使用Application.Run(new MainForm());和我的Application.AddMessageFilter(new Logger()); )。

Does anyone have an idea (or a walk around) on how to get the clicked control in the application (in .Net 3.5)? 是否有人对如何在应用程序中(在.Net 3.5中)获得单击的控件有想法(或解决方案)?

I've been using an amazing little application called Snoop for some time now that I think does exactly what you're after, it's open source (C#) and may be of use to you if you can find out how it works. 我一直在使用一个名为Snoop的神奇小应用程序一段时间,因为我认为它确实可以满足您的需求,它是开放源代码(C#),如果您能了解它的工作原理,可能会对您有用。 (All WPF developers should get this and no I don't work on Snoop lol) (所有WPF开发人员都应该得到这个,不,我不会在Sno​​op上工作)

http://snoopwpf.codeplex.com/ http://snoopwpf.codeplex.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM