Custom item in context menu
-
How can an item be added to context menu that pops up when highlighting a part of text in any program and right clicking ? And a code should be associated with that which processes the piece of text highlighted. The item should be added to every programs context menu when text can be selected;ex Internet Explorer , Firefox , notepad, etc... I have some general methods in my mind from my studies revolving around windows internals. But no specifics. What is the best way to do it ? can this be done by writing code in kernel mode ? how ? is it necessary ? what are other methods which involve user mode programming ?
-
How can an item be added to context menu that pops up when highlighting a part of text in any program and right clicking ? And a code should be associated with that which processes the piece of text highlighted. The item should be added to every programs context menu when text can be selected;ex Internet Explorer , Firefox , notepad, etc... I have some general methods in my mind from my studies revolving around windows internals. But no specifics. What is the best way to do it ? can this be done by writing code in kernel mode ? how ? is it necessary ? what are other methods which involve user mode programming ?
You cannot add items to every context menu on the system; not all of them are dynamic. You can add to Windows Explorer and (probably) IE by writing extensions or via other published interfaces. Try a Google search for samples and articles on the subjects.
One of these days I'm going to think of a really clever signature.
-
You cannot add items to every context menu on the system; not all of them are dynamic. You can add to Windows Explorer and (probably) IE by writing extensions or via other published interfaces. Try a Google search for samples and articles on the subjects.
One of these days I'm going to think of a really clever signature.
Richard MacCutchan wrote:
You cannot add items to every context menu on the system
Even by coding in assembly level ? Can a program be written that when it runs overrides the default belavior of the system ? When selecting and right clicking any piece of text , our custom context menu appears in place of the default ? I mean overriding this behavior on the system-wide level.No matter in IE or any other programs as long as a text selection is concerned.
-
Richard MacCutchan wrote:
You cannot add items to every context menu on the system
Even by coding in assembly level ? Can a program be written that when it runs overrides the default belavior of the system ? When selecting and right clicking any piece of text , our custom context menu appears in place of the default ? I mean overriding this behavior on the system-wide level.No matter in IE or any other programs as long as a text selection is concerned.
devboycpp wrote:
Even by coding in assembly level ?
Why do you think that will make a difference?
devboycpp wrote:
overrides the default belavior of the system ?
Possibly by windows hooking but you would still need to check which program is active every time you trap a message, before you could decide what action to take. The problem is that context menus are not generated in a single place within the system so you cannot have a universal piece of code to intercept them all.
One of these days I'm going to think of a really clever signature.
-
devboycpp wrote:
Even by coding in assembly level ?
Why do you think that will make a difference?
devboycpp wrote:
overrides the default belavior of the system ?
Possibly by windows hooking but you would still need to check which program is active every time you trap a message, before you could decide what action to take. The problem is that context menus are not generated in a single place within the system so you cannot have a universal piece of code to intercept them all.
One of these days I'm going to think of a really clever signature.
Richard MacCutchan wrote:
Why do you think that will make a difference?
I think you are familiar with windows debugging techniques using tools like WinDbg. By using them we can go deep in kernel and put breakpoints in kernel code or every where in memory. As all usermode programs' API interactions eventually goes in kernel and for similar functionalities like showing context menu similar kernel code is invoked. So by using techniques like modifying an API function parameter before it is passed to the API(I am just guessing) or alike, can we modify the system behavior. I mean programs use a common API for similar functionality(like context menu), so by installing our code before the API is invoked maybe we can modify the behavior;Techniques like import address table modification.
Richard MacCutchan wrote:
The problem is that context menus are not generated in a single place within the system so you cannot have a universal piece of code to intercept them all.
But they are generated by using common APIs, aren't they ?
-
Richard MacCutchan wrote:
Why do you think that will make a difference?
I think you are familiar with windows debugging techniques using tools like WinDbg. By using them we can go deep in kernel and put breakpoints in kernel code or every where in memory. As all usermode programs' API interactions eventually goes in kernel and for similar functionalities like showing context menu similar kernel code is invoked. So by using techniques like modifying an API function parameter before it is passed to the API(I am just guessing) or alike, can we modify the system behavior. I mean programs use a common API for similar functionality(like context menu), so by installing our code before the API is invoked maybe we can modify the behavior;Techniques like import address table modification.
Richard MacCutchan wrote:
The problem is that context menus are not generated in a single place within the system so you cannot have a universal piece of code to intercept them all.
But they are generated by using common APIs, aren't they ?
devboycpp wrote:
we can go deep in kernel and put breakpoints in kernel code or every where in memory.
I don't think so, kernel code is not accessible by user programs.
devboycpp wrote:
But they are generated by using common APIs, aren't they ?
Possibly, but I'm not sure it's that straightforward.
One of these days I'm going to think of a really clever signature.
-
devboycpp wrote:
we can go deep in kernel and put breakpoints in kernel code or every where in memory.
I don't think so, kernel code is not accessible by user programs.
devboycpp wrote:
But they are generated by using common APIs, aren't they ?
Possibly, but I'm not sure it's that straightforward.
One of these days I'm going to think of a really clever signature.
Richard MacCutchan wrote:
I don't think so, kernel code is not accessible by user programs.
I guess you are not familiar with WinDbg tool. It is a debugger which can run in kernel mode. And in kernel mode debugging ,breakpoints can be set everywhere including kernel code.
Richard MacCutchan wrote:
Possibly, but I'm not sure it's that straightforward.
Sure it is not so. Thanks for comment anyway.
-
Richard MacCutchan wrote:
I don't think so, kernel code is not accessible by user programs.
I guess you are not familiar with WinDbg tool. It is a debugger which can run in kernel mode. And in kernel mode debugging ,breakpoints can be set everywhere including kernel code.
Richard MacCutchan wrote:
Possibly, but I'm not sure it's that straightforward.
Sure it is not so. Thanks for comment anyway.
-
devboycpp wrote:
a debugger which can run in kernel mode.
I have never used WinDbg, something else to add to my list of things to learn.
One of these days I'm going to think of a really clever signature.
-
Why, is it relevant to anything?
One of these days I'm going to think of a really clever signature.
-
Richard MacCutchan wrote:
Why, is it relevant to anything?
No just the reason is why people put their age in their profile. Just to let people know. I don't mean to relate it to anything.
-
Sorry I don't understand. I don't have my age in my profile and nor do most people, so where did this question come from?
One of these days I'm going to think of a really clever signature.
Richard MacCutchan wrote:
I don't have my age in my profile and nor do most people, so where did this question come from?
But some have their age in their profile. For example you have told in your profile "I hope someday I will become a real programmer" because you want others to know it. Otherwise you could just say what does it have to do with other people. I don't care. Probably you don't want others to know your age for personal reasons and I respect it.
-
Richard MacCutchan wrote:
I don't have my age in my profile and nor do most people, so where did this question come from?
But some have their age in their profile. For example you have told in your profile "I hope someday I will become a real programmer" because you want others to know it. Otherwise you could just say what does it have to do with other people. I don't care. Probably you don't want others to know your age for personal reasons and I respect it.
What people put in their profile may not have anything to do with reality, don't take it too literally.
devboycpp wrote:
I hope someday I will become a real programmer
I still hope this.
One of these days I'm going to think of a really clever signature.
-
How can an item be added to context menu that pops up when highlighting a part of text in any program and right clicking ? And a code should be associated with that which processes the piece of text highlighted. The item should be added to every programs context menu when text can be selected;ex Internet Explorer , Firefox , notepad, etc... I have some general methods in my mind from my studies revolving around windows internals. But no specifics. What is the best way to do it ? can this be done by writing code in kernel mode ? how ? is it necessary ? what are other methods which involve user mode programming ?
As already noted by Richard, this can't be simply done if there is no method provided like for the Explorer. I will try to explain how context menus are handled: When clicking the right mouse button, the window under the mouse cursor will get a
WM_CONTEXTMENU
message. When pressing the context menu button on the keyboard (commonly left of the right ctrl key), the window which has the focus will receive this message. TheWM_CONTEXTMENU
handler will then create and show the menu. This is usually done by loading it from resources. But the complete menu or portions may be also created dynamically by code. It is also common practice to modify resource based menus dynamically according the current context (gray out, remove, add, or change items and sub menus). To modify a menu, you must know the handle that is assigned upon menu creation (with resource based menus the handle of the sub-menu because that contains the items). If you want to insert new items, you must also know about the existing items (order, position, sub menus, separators). If you really want to try it, you must hook the API functionsCreateMenu()
,CreatePopupMenu()
, andTrackPopupMenu[Ex]()
. But I'm not sure if this will work.