使用净外部应用程序检测的拖放操作 [英] Detect drag and drop operations in an external application using .Net

查看:292
本文介绍了使用净外部应用程序检测的拖放操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测拖放操作中的外部应用程序,这可能吗?我觉得写一个钩子,以检测这些操作。任何人都可以点我在正确的方向,只要该消息或API函数,我可以尝试钩来检测拖放放大器;丢弃事件?我想这样做在C#。

I need to detect drag and drop operations in an external application, is it possible? I thought of writing a hook to detect these operations. Can anybody point me in the right direction as far as which messages or api functions I could attempt to hook to detect the Drag & Drop events? I want to do this in C#.

在此先感谢。

推荐答案

有两个明显的路径,你可以去尝试这一点。

There are two obvious paths you can go down to attempt this.

首先,是勾参与介导拖/放操作的OLE函数。这是假设其他应用程序正在使用真正的拖放并没有一些内部唯一版本。 Determing这已经超出了我的能力 - 无需访问程序 - 但如果它可以从这个外部应用程序拖动到其他应用程序窗口(包括台式机),它是一个很好的迹象,该应用程序使用的是真正的东西

The first, is to hook the OLE functions involved in mediating drag/drop operations. This assumes that the other application is using real drag and drop and not some internal only version. Determing this is beyond my ability - without access to the program - but if its possible to drag from this external application to some other applications window (including the desktop) its a good indication that the app is using the real stuff.

你需要连接的功能是 RegisterDragDrop ,虽然的DoDragDrop 也可感兴趣。 RegisterDragDrop 被称为注册一个放置目标,并给你一个机会来包装下降目标在你想要的满耳( presumably IPC'ing到实际的应用程序),RevokeDragDrop然后通上注册,但现在你的包装对象来代替。 ::下降目标落是presumably在这里,你会做你的大部分IPC的。

The function you'd need to hook is RegisterDragDrop, though DoDragDrop may also be of interest. RegisterDragDrop is called to register a drop target, and gives you an opportunity to wrap the IDropTarget in the maner you desire (presumably IPC'ing into your actual app), RevokeDragDrop and then pass the registration on, but now with your wrapper object instead. IDropTarget::Drop is presumably where you'll do the bulk of your IPC.

第二,是通过注射的Windows钩到应用程序中。如果您明白,触发拖动的用户操作,而且可以检测到这只是听话作为你将有一个拖动操作和普通键盘/鼠标操作区别开来。有问题的钩子是 WH_CALLWNDPROC 挂钩,用的调用SetWindowsHookEx 。基本上,你定义了一个的WndProc 它可以获取所有应用程序窗口确实消息(包括鼠标移动)及其由你来决定什么时候拖动操作的开始和停止。

The second, is by injecting a Windows hook into the application. This is only tractable if you understand the user actions that trigger a drag, and can detect them as you're going to have to distinguish between a drag operation and normal keyboard/mouse actions. The hook in question is the WH_CALLWNDPROC hook, registered with SetWindowsHookEx. Basically, you define a WndProc which gets all the messages the applications window does (including mouse movement) and its up to you to determine when a drag operation starts and when it stops.

在这两种情况下,的code很多可能被写在C#。以P \调用你可以在 SetWindowsHookEx函数,并且可以实现COM对象(推而广之,包装在C#中的COM对象),以及。逸岸,有一个 下降目标类已经研究。 NET 2.0;这可能是可见的COM已

In either case, alot of the code can be written in C#. With p\invoke you can get at SetWindowsHookEx, and you can implement COM objects (and by extension, wrappers for those COM objects) in C# as well. Infact, there's an IDropTarget class already in .NET 2.0; which might be COM visible already.

不幸的是,挂钩的API是非常低的水平,你一般会在C或C ++工作做成任何事情。我听说过走弯路的好东西,加上其来自微软。

Unfortunately, hooking APIs is very low level and you're generally going to have to work in C or C++ to get anything done. I've heard good things about Detours, plus its from Microsoft.

这篇关于使用净外部应用程序检测的拖放操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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