System wide right click context hook

£可爱£侵袭症+ 提交于 2019-12-11 08:57:27

问题


**Hello..

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.

How to do this?

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

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

so please help me.**


回答1:


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.

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.

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. Forget about changing the right-click menu. Open a window next to the point of selection with whatever content you want, and let the application show its own right-click menu.
  2. If the user right-clicks while, say, pressing shift, show your own right-click menu, and don't pass the message to the application. So the user will see only one menu, which is yours. The user must of course be aware of this combination.


来源:https://stackoverflow.com/questions/7509483/system-wide-right-click-context-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!