我可以使用 Global System Hooks 来捕获点击了哪个文件吗? [英] Can i use Global System Hooks to capture which file was clicked on?

查看:25
本文介绍了我可以使用 Global System Hooks 来捕获点击了哪个文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Windows 编程的新手,主要是做 Java(Java SE、Java ME、Android、Java EE),所以要详细和温和.

I am new to Windows programming, mostly done Java(Java SE, Java ME, Android, Java EE), so be detailed and gentle.

我想捕获在 Windows 中单击的文件/路径的名称,例如单击桌面上的文件"?

I want to capture "the name of the file/path that was clicked in windows, like clicking a file on the desktop"?

进一步研究 http://www.codeproject.com/Articles/6362/Global-System-Hooks-in-NET,这是一个使用 Global System Hooks 来捕捉鼠标事件(如坐标、点击等)的 c#/c++ 小程序.

Further research http://www.codeproject.com/Articles/6362/Global-System-Hooks-in-NET, which is a small c#/c++ nice app that uses Global System Hooks, to capture mouse events such as coordinates,clicks,etc.

那么,捕获文件图标事件的正确 API 或全局系统钩子是什么?

So what is the right API or Global System Hook that captures events on file icons?

推荐答案

没有单一的 API 可以提供如此详细的信息.

There is no single API that provides that level of detail.

SetWindowsHookEx()WH_MOUSEWH_MOUSE_LL 钩子,或 传递的 WM_INPUT 消息RegisterRawInputDevices(),可以判断鼠标何时在交互,GetCursorPos() 函数可以告诉你点击时鼠标光标在屏幕上的位置,但它不能告诉你它在点击什么.你必须手动弄清楚.

The WH_MOUSE and WH_MOUSE_LL hooks of SetWindowsHookEx(), or the WM_INPUT message delivered by RegisterRawInputDevices(), can tell when the mouse is being intereacted with, and the GetCursorPos() function can tell you where the mouse cursor is located onscreen at the time of a click, but it cannot tell you what it is clicking on. You have to figure that out manually.

例如,Desktop 是作为 ListView 控件实现的,因此您可以使用 WindowFromPoint()GetDesktopWindow() 函数来检查鼠标是否位于对应于桌面窗口本身而不是应用程序窗口的坐标,如果是,则使用 LVM_HITTESTLVM_GETITEM 消息来确定桌面上的哪个图标被点击并提取其显示文本.然后使用 SHGetDesktopFolder() 函数和 IShellFolder 接口或 SHParseDisplayName() 函数来解析该文本并查看它是否返回PIDL 表示路径/文件,如果是,则使用 SHGetPathFromIDList() 获取实际路径/文件名.

For instance, the Desktop is implemented as a ListView control, so you can use the WindowFromPoint() and GetDesktopWindow() functions to check if the mouse is located at coordinates corresponding to the desktop window itself instead of an application window, and if so then use the LVM_HITTEST and LVM_GETITEM messages to determine which icon onthe desktop is being clicked on and extract its display text. Then use the SHGetDesktopFolder() function and the IShellFolder interface, or the SHParseDisplayName() function, to parse that text and see if it returns a PIDL that represents a path/file, and if so then use SHGetPathFromIDList() to get the actual path/file name.

如果您想用 Windows 资源管理器应用程序做同样的事情,它会变得有点复杂.使用 WindowFromPoint()GetWindowThreadProcessId()OpenProcess()EnumProcessModules() 来判断鼠标是否结束了 Windows 资源管理器应用程序.但是,它的 UI 从 Windows 版本更改为下一个,但要点是您必须通过 AttachThreadInput()GetActiveWindow() 手动定位焦点控件,检查如果它是 TreeView/ListView 控件,如果是,则使用特定于控件的消息来获取有关鼠标光标坐标下的项目/图标的信息,并再次使用 IShellFolder 来找出该项目/图标实际代表.

If you want to do the same thing with the Windows Explorer app, it gets a bit more complicated. Use WindowFromPoint(), GetWindowThreadProcessId(), OpenProcess(), and EnumProcessModules() to determine if the mouse is over the Windows Explorer app. However, its UI changes from on Windows version to the next, but the jist is that you have to manually locate the focused control via AttachThreadInput() and GetActiveWindow(), check if it is a TreeView/ListView control, and if so then use control-specific messages to get information about the item/icon underneath the mouse cursor coordinates, and use IShellFolder again to figure out what the text of that item/icon actually represents.

Shell 编程是一个非常复杂的系统,不适合假装进行交互.所以你需要问问自己,你为什么首先需要这些信息?

Shell programming is very complex system and not for the feint of heart to interact with. So you need to ask yourself, why do you need this information in the first place?

这篇关于我可以使用 Global System Hooks 来捕获点击了哪个文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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