Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. Custom item in context menu

Custom item in context menu

Scheduled Pinned Locked Moved Windows API
questionlounge
17 Posts 3 Posters 47 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devboycpp
    wrote on last edited by
    #1

    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 ?

    L J 2 Replies Last reply
    0
    • D devboycpp

      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 ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      D 1 Reply Last reply
      0
      • L Lost User

        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.

        D Offline
        D Offline
        devboycpp
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • D devboycpp

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          D 1 Reply Last reply
          0
          • L Lost User

            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.

            D Offline
            D Offline
            devboycpp
            wrote on last edited by
            #5

            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 ?

            L 1 Reply Last reply
            0
            • D devboycpp

              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 ?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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.

              D 1 Reply Last reply
              0
              • L Lost User

                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.

                D Offline
                D Offline
                devboycpp
                wrote on last edited by
                #7

                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.

                L 1 Reply Last reply
                0
                • D devboycpp

                  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.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  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.

                  D 1 Reply Last reply
                  0
                  • L Lost User

                    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.

                    D Offline
                    D Offline
                    devboycpp
                    wrote on last edited by
                    #9

                    Would you mind to say how old you are ? Just curiosity.

                    L 1 Reply Last reply
                    0
                    • D devboycpp

                      Would you mind to say how old you are ? Just curiosity.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Old!

                      One of these days I'm going to think of a really clever signature.

                      D 1 Reply Last reply
                      0
                      • L Lost User

                        Old!

                        One of these days I'm going to think of a really clever signature.

                        D Offline
                        D Offline
                        devboycpp
                        wrote on last edited by
                        #11

                        Just wanted to know your age .

                        L 1 Reply Last reply
                        0
                        • D devboycpp

                          Just wanted to know your age .

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Why, is it relevant to anything?

                          One of these days I'm going to think of a really clever signature.

                          D 1 Reply Last reply
                          0
                          • L Lost User

                            Why, is it relevant to anything?

                            One of these days I'm going to think of a really clever signature.

                            D Offline
                            D Offline
                            devboycpp
                            wrote on last edited by
                            #13

                            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.

                            L 1 Reply Last reply
                            0
                            • D devboycpp

                              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.

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #14

                              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.

                              D 1 Reply Last reply
                              0
                              • L Lost User

                                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.

                                D Offline
                                D Offline
                                devboycpp
                                wrote on last edited by
                                #15

                                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.

                                L 1 Reply Last reply
                                0
                                • D devboycpp

                                  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.

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #16

                                  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.

                                  1 Reply Last reply
                                  0
                                  • D devboycpp

                                    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 ?

                                    J Offline
                                    J Offline
                                    Jochen Arndt
                                    wrote on last edited by
                                    #17

                                    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. The WM_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 functions CreateMenu(), CreatePopupMenu(), and TrackPopupMenu[Ex](). But I'm not sure if this will work.

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups