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. C / C++ / MFC
  4. menu [modified]

menu [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
7 Posts 3 Posters 0 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.
  • A Offline
    A Offline
    Anilkumar K V
    wrote on last edited by
    #1

    I have to add a menu item on right clicking selected text, invoke my command handler and get the selected text, from any text document 1. How to add menu item to the existing windows generated menu 2. How to get the selected text to the menu handler program Thanks Anil -- modified at 4:31 Tuesday 13th February, 2007

    T 1 Reply Last reply
    0
    • A Anilkumar K V

      I have to add a menu item on right clicking selected text, invoke my command handler and get the selected text, from any text document 1. How to add menu item to the existing windows generated menu 2. How to get the selected text to the menu handler program Thanks Anil -- modified at 4:31 Tuesday 13th February, 2007

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      then, what's your question ? where's your problem ? what have you tried already ? where are you blocked ?


      [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

      A 1 Reply Last reply
      0
      • T toxcct

        then, what's your question ? where's your problem ? what have you tried already ? where are you blocked ?


        [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

        A Offline
        A Offline
        Anilkumar K V
        wrote on last edited by
        #3

        I have to add a menu item on right clicking selected text, invoke my command handler and get the selected text, from any text document 1. How to add menu item to the existing windows generated menu 2. How to get the selected text to the menu handler program

        J 1 Reply Last reply
        0
        • A Anilkumar K V

          I have to add a menu item on right clicking selected text, invoke my command handler and get the selected text, from any text document 1. How to add menu item to the existing windows generated menu 2. How to get the selected text to the menu handler program

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          Use WM_CONTEXTMENU. The handler is called OnContextMenu). There you can use code like this:

          //Start CSM
          CMenu menu; menu.LoadMenu( IDR_CONTEXT_MENUS);
          CMenu* pContextMenu = menu.GetSubMenu( 1); // context menu ViewCSM
          CMenu* pWorkMenu = menu.GetSubMenu( 2); // context menu WorkCSM
          if( pWorkMenu) {
          MergeMenu( pContextMenu, pWorkMenu);
          }
          pContextMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);

          Instead of MergeMenu, you might as well add an item. For this to work, I have made a menu-resource where I place all my context menus as submenus. The code that handles the selected menu item does so using the menu item IDs I gave in the resource. The last paramter to TrackPopupMenu() defines theclass that is the parent for the menus and gets the command messages.


          "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

          A 1 Reply Last reply
          0
          • J jhwurmbach

            Use WM_CONTEXTMENU. The handler is called OnContextMenu). There you can use code like this:

            //Start CSM
            CMenu menu; menu.LoadMenu( IDR_CONTEXT_MENUS);
            CMenu* pContextMenu = menu.GetSubMenu( 1); // context menu ViewCSM
            CMenu* pWorkMenu = menu.GetSubMenu( 2); // context menu WorkCSM
            if( pWorkMenu) {
            MergeMenu( pContextMenu, pWorkMenu);
            }
            pContextMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);

            Instead of MergeMenu, you might as well add an item. For this to work, I have made a menu-resource where I place all my context menus as submenus. The code that handles the selected menu item does so using the menu item IDs I gave in the resource. The last paramter to TrackPopupMenu() defines theclass that is the parent for the menus and gets the command messages.


            "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

            A Offline
            A Offline
            Anilkumar K V
            wrote on last edited by
            #5

            Can we add the menu item via registry as we add menu items, on right clicking files,folder etc

            T J 2 Replies Last reply
            0
            • A Anilkumar K V

              Can we add the menu item via registry as we add menu items, on right clicking files,folder etc

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              i think you're wanting this[^]


              [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

              1 Reply Last reply
              0
              • A Anilkumar K V

                Can we add the menu item via registry as we add menu items, on right clicking files,folder etc

                J Offline
                J Offline
                jhwurmbach
                wrote on last edited by
                #7

                What do you mean? Where you get your menu text and menu ID does not matter: CMenu allows you to add arbitrary text and numbers. You may as well load it from registry entries. If you want to change a menu from a menu bar, you would need to handle WM_INITMENU or override CWnd::OnInitMenu. There you can modify the menu - to the point of assembling a completely different menu.


                "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                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