1

**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.**

aarti
  • 175
  • 2
  • 15

1 Answers1

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.
Eran
  • 21,632
  • 6
  • 56
  • 89
  • is it possible to add context menu by EXE injection? – aarti Sep 22 '11 at 07:10
  • @aarti, when your code is hooking another process, it is running within that process' address space. Basically, you can do anything you want, as if your code is part of the executable you're hooking. However, to do complicated things, you must be intimately familiar with the application you're hooking, and _that's_ the biggest problem. You can reverse engineer a specific application and add all sort of additions, but for the general case, you need a general solution. Do you have a specific application in mind, or are you looking for a general solution? – Eran Sep 22 '11 at 08:01
  • No ,i have no specific application ,i need this facility [DICTIONARY] in all exe applications that user opens.so i need to display menuitem in almost all apps.Like notepad,winword,mozila,powerpoint,vb6,visual studio etc. – aarti Sep 22 '11 at 08:30