系统范围的右键单击上下文挂钩 [英] System wide right click context hook

查看:92
本文介绍了系统范围的右键单击上下文挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**你好..

我正在创建英语到古吉拉特语词典WinForm应用程序.

i am creating English To Gujarati Dictionary WinForm Application.

我需要在右键单击上下文菜单上设置一个系统范围的钩子,以选择文本.

I need to set a system wide hook to the right click context menu on for text selection.

这表示该应用程序在运行时,并且如果用户从任何程序中选择单词并右键单击它,则该单词的含义应显示为菜单项.

it means when this application is running,and if user selects word from any program and right click on it gujarati meaning of that word should be displayed as menu item.

该怎么做?

或其他任何选项,例如注册编程,shell扩展等...?

or any other options like Registery Programming,shell extentions etc...?

即使您说不可能,我也必须这样做.

i have to do this,even if you say its not possible.

所以请帮助我.**

推荐答案

钩住鼠标活动很容易.请参见 SetWindowsHookEx ,还有很多关于SO挂钩的问题.这样,您可以知道何时右键单击鼠标.

Hooking the mouse activity is the easy part. See SetWindowsHookEx, and lots of questions regarding hooking in SO. This way, you can tell when the mouse is right-clicked.

获取所选文本是更难的部分.请参见 WindowFromPoint ,对于初学者.您必须识别该控件,并在适当的情况下从中获取选定的文本.如果控件很复杂,使用简单的Win32函数将无法总是做到这一点.

Getting the selected text is the harder part. See WindowFromPoint, for starters. You'd have to recognize the control, and if appropriate get the selected text from it. This will not always be possible using simple Win32 functions, if the control is complex.

将翻译添加到右键菜单可能是不可能的部分.将资源添加到资源管理器上下文菜单不是问题,因为资源管理器提供了这种可能性.但是,各种应用程序将具有各种右键单击菜单,而没有扩展它们的方法.无论出于何种原因,他们甚至可能不使用Win32菜单.更好的选择IMO将是以下之一:

Adding the translation to the right-click menu is probably the impossible part. Adding stuff to explorer context menu is not a problem, because explorer provides that possibility. But various applications will have various right-click menus, without a way to extend them. They might not even use Win32 for the menus, for whatever reason. A better option, IMO, would be one of the following:

  1. 忘记更改右键单击菜单.在选择点旁边打开一个窗口,其中包含您想要的任何内容,然后让该应用程序显示其自己的右键菜单.
  2. 如果用户在按住Shift键的同时单击鼠标右键,则显示您自己的右键单击菜单,并且不要将消息传递给应用程序.因此,用户只会看到一个菜单,这就是您的菜单.用户当然必须意识到这种组合.

这篇关于系统范围的右键单击上下文挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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