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. Context menu problem

Context menu problem

Scheduled Pinned Locked Moved C / C++ / MFC
helplearning
13 Posts 2 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.
  • G gajendrakashyap

    Hi everyone !! I've a dialog based application in which I've added a context menu. I had previously defined a menu similar to file menu which works fine. Recently I added a context menu for one of the dialogs. It is not working :(( I checked the resource file for any duplicate id's and corrected that also but nothing seems to be helping me. Here is what I did. 1. Added a context menu in Resource->Menu. 2. Added a context menu command handler for that dialog. 3. Added command handler for each of the ID in this menu. When I compile, build and run the application it gives no errors but the commands from this context menu are not working. :(( When I try implementing a context menu with another project it works fine. :confused: Please help Thanks, Gajendra

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #2

    Can you show a snippet code

    _**


    **_

    WhiteSky


    G 1 Reply Last reply
    0
    • H Hamid Taebi

      Can you show a snippet code

      _**


      **_

      WhiteSky


      G Offline
      G Offline
      gajendrakashyap
      wrote on last edited by
      #3

      This is in message maps: ON_COMMAND(ID_DIR_REVN_MENU, On_Dir_Revn_Menu) ----------------------------------------------------------------------- I've customised the display of context menu to deligate to another function. The context menu code is loaded properly and displayed. // called from the original OnContextMenu void CFPLN_PAGE_Dialog::On_Fpln_Revn_Menu(CPoint point) { point.x = 90; point.y = 95; ClientToScreen(&point); CMenu m_Fpln_Revn_Menu, *m_Ptr_ContextMenu; m_Fpln_Revn_Menu.LoadMenu(IDR_FPLN_REVN_MENU); m_Ptr_ContextMenu = m_Fpln_Revn_Menu.GetSubMenu(0); ASSERT(m_Fpln_Revn_Menu); m_Ptr_ContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, AfxGetMainWnd()); } ----------------------------------------------------------------------- Then the command handler code is: void CFPLN_PAGE_Dialog::On_Dir_Revn_Menu() { // TODO: Add your command handler code here AfxMessageBox("dir revn menu"); } Is this ok for you to guess something...? Let me know if you want to know more about the problem. You can mail to me: "gajendra.kashyap@valtech.co.in" Thanks, Gajendra

      H 1 Reply Last reply
      0
      • G gajendrakashyap

        This is in message maps: ON_COMMAND(ID_DIR_REVN_MENU, On_Dir_Revn_Menu) ----------------------------------------------------------------------- I've customised the display of context menu to deligate to another function. The context menu code is loaded properly and displayed. // called from the original OnContextMenu void CFPLN_PAGE_Dialog::On_Fpln_Revn_Menu(CPoint point) { point.x = 90; point.y = 95; ClientToScreen(&point); CMenu m_Fpln_Revn_Menu, *m_Ptr_ContextMenu; m_Fpln_Revn_Menu.LoadMenu(IDR_FPLN_REVN_MENU); m_Ptr_ContextMenu = m_Fpln_Revn_Menu.GetSubMenu(0); ASSERT(m_Fpln_Revn_Menu); m_Ptr_ContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, AfxGetMainWnd()); } ----------------------------------------------------------------------- Then the command handler code is: void CFPLN_PAGE_Dialog::On_Dir_Revn_Menu() { // TODO: Add your command handler code here AfxMessageBox("dir revn menu"); } Is this ok for you to guess something...? Let me know if you want to know more about the problem. You can mail to me: "gajendra.kashyap@valtech.co.in" Thanks, Gajendra

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #4

        Whats problem with this code it work,when you run this code you see a contextmenu in 90x95(create a menu in resource and event handler and run ...not problem)but you need to use CPoint point; GetCursorPos(&point); //for get current position instead point.x&point.y=value.

        _**


        **_

        WhiteSky


        G 1 Reply Last reply
        0
        • H Hamid Taebi

          Whats problem with this code it work,when you run this code you see a contextmenu in 90x95(create a menu in resource and event handler and run ...not problem)but you need to use CPoint point; GetCursorPos(&point); //for get current position instead point.x&point.y=value.

          _**


          **_

          WhiteSky


          G Offline
          G Offline
          gajendrakashyap
          wrote on last edited by
          #5

          The problem is that the commands from context menu are not working. The corresponding mapped function is not called when something is selected in the menu. Gaj

          H 1 Reply Last reply
          0
          • G gajendrakashyap

            The problem is that the commands from context menu are not working. The corresponding mapped function is not called when something is selected in the menu. Gaj

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #6

            Are you sure ids are unique it seems you code doesnt has a problem

            _**


            **_

            WhiteSky


            G 1 Reply Last reply
            0
            • H Hamid Taebi

              Are you sure ids are unique it seems you code doesnt has a problem

              _**


              **_

              WhiteSky


              G Offline
              G Offline
              gajendrakashyap
              wrote on last edited by
              #7

              Yes the IDs are unique. I've ResOrgAddin tool to check that. I got the problem just a few mins back. I don't know if I can load an image here but the I'll try to explain the design. I've a main dialog for the application, lets call this parent. I've several child dialogs which are displayed overlayed on this parent dialog. I implemented context menu only for one of the child dialog... it did not work as expected. Although the context menu was displayed the commands were not getting generated ... Surprising. Now I implemented the contextmenu on the parent dialog and it works as expected jst need to control the display on right dialog. I don't think it is the right way to do... but it is working. If i could send and handle the commands from the right dialog on which context menu is displayed would be the best situation. Let me know your valuable opinion. :) Thanks, Gaj

              H 1 Reply Last reply
              0
              • G gajendrakashyap

                Yes the IDs are unique. I've ResOrgAddin tool to check that. I got the problem just a few mins back. I don't know if I can load an image here but the I'll try to explain the design. I've a main dialog for the application, lets call this parent. I've several child dialogs which are displayed overlayed on this parent dialog. I implemented context menu only for one of the child dialog... it did not work as expected. Although the context menu was displayed the commands were not getting generated ... Surprising. Now I implemented the contextmenu on the parent dialog and it works as expected jst need to control the display on right dialog. I don't think it is the right way to do... but it is working. If i could send and handle the commands from the right dialog on which context menu is displayed would be the best situation. Let me know your valuable opinion. :) Thanks, Gaj

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #8

                Im wondering you are using same code in two place parent and child in parent its working and in child its not working you can show context_menu but you cant run items in this menu on child menu.I tested like you step to step and it worked

                _**


                **_

                WhiteSky


                G 1 Reply Last reply
                0
                • H Hamid Taebi

                  Im wondering you are using same code in two place parent and child in parent its working and in child its not working you can show context_menu but you cant run items in this menu on child menu.I tested like you step to step and it worked

                  _**


                  **_

                  WhiteSky


                  G Offline
                  G Offline
                  gajendrakashyap
                  wrote on last edited by
                  #9

                  Can you explain me your design if it differs from mine in some way? thanks for your help. Gajendra

                  H 1 Reply Last reply
                  0
                  • G gajendrakashyap

                    Can you explain me your design if it differs from mine in some way? thanks for your help. Gajendra

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #10

                    well im writting a program (a parent dialog and a child) and then: (1)Create a menu in resource and declare handler for items in main class (2) im creating a button and insert these codes to it CMenu m_Fpln_Revn_Menu, *m_Ptr_ContextMenu; CPoint point; GetCursorPos(&point); m_Fpln_Revn_Menu.LoadMenu(IDR_MENU1); m_Ptr_ContextMenu = m_Fpln_Revn_Menu.GetSubMenu(0); m_Ptr_ContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, AfxGetMainWnd()); (3) and running my program (4)when im clicking this button i can see a context_menu and when i click on items these works (5) then im writting like these codes for child dialog and its working Now you have this prolem with all your programs or only this program

                    _**


                    **_

                    WhiteSky


                    G 1 Reply Last reply
                    0
                    • H Hamid Taebi

                      well im writting a program (a parent dialog and a child) and then: (1)Create a menu in resource and declare handler for items in main class (2) im creating a button and insert these codes to it CMenu m_Fpln_Revn_Menu, *m_Ptr_ContextMenu; CPoint point; GetCursorPos(&point); m_Fpln_Revn_Menu.LoadMenu(IDR_MENU1); m_Ptr_ContextMenu = m_Fpln_Revn_Menu.GetSubMenu(0); m_Ptr_ContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, AfxGetMainWnd()); (3) and running my program (4)when im clicking this button i can see a context_menu and when i click on items these works (5) then im writting like these codes for child dialog and its working Now you have this prolem with all your programs or only this program

                      _**


                      **_

                      WhiteSky


                      G Offline
                      G Offline
                      gajendrakashyap
                      wrote on last edited by
                      #11

                      I have problem with only this one becuase it works on others. I can't reveal the complete code to you :sigh: But its ok, I think I know the solution what needs to be done. Thanks much for your time and help. :) Regards, Gajendra

                      H 1 Reply Last reply
                      0
                      • G gajendrakashyap

                        I have problem with only this one becuase it works on others. I can't reveal the complete code to you :sigh: But its ok, I think I know the solution what needs to be done. Thanks much for your time and help. :) Regards, Gajendra

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #12

                        if you create a new menu and repeat this stage whats happen?same problem

                        _**


                        **_

                        WhiteSky


                        G 1 Reply Last reply
                        0
                        • H Hamid Taebi

                          if you create a new menu and repeat this stage whats happen?same problem

                          _**


                          **_

                          WhiteSky


                          G Offline
                          G Offline
                          gajendrakashyap
                          wrote on last edited by
                          #13

                          Till now I had only single context menu for that dialog. Will try to add another one for another dialog and lets see then. Regards, Gajendra

                          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