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. Message handling/command routing

Message handling/command routing

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomdesign
8 Posts 4 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.
  • F Offline
    F Offline
    Fredrik Skog
    wrote on last edited by
    #1

    E.g. I have a toolbar to which I can add buttons. Each button has a menu with two menu items: "Configure" and "Remove". The menu is displayed when the right mouse button is clicked on the button. The menu is a child of the toolbar, thus having the message routing taken care of in the toolbar. The question is, how can I tell which button the menu was invoked on, in order to know which button to remove when the user selects "Remove"? Is my design all wrong or what? I am going (more) insane over this... Cheers,
    /Fredrik

    Sonork ID: 100.11430:PhatBoy

    J N 3 Replies Last reply
    0
    • F Fredrik Skog

      E.g. I have a toolbar to which I can add buttons. Each button has a menu with two menu items: "Configure" and "Remove". The menu is displayed when the right mouse button is clicked on the button. The menu is a child of the toolbar, thus having the message routing taken care of in the toolbar. The question is, how can I tell which button the menu was invoked on, in order to know which button to remove when the user selects "Remove"? Is my design all wrong or what? I am going (more) insane over this... Cheers,
      /Fredrik

      Sonork ID: 100.11430:PhatBoy

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      I'm not 100% sure about this, but maybe GetFocus on the command handler will do... Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • F Fredrik Skog

        E.g. I have a toolbar to which I can add buttons. Each button has a menu with two menu items: "Configure" and "Remove". The menu is displayed when the right mouse button is clicked on the button. The menu is a child of the toolbar, thus having the message routing taken care of in the toolbar. The question is, how can I tell which button the menu was invoked on, in order to know which button to remove when the user selects "Remove"? Is my design all wrong or what? I am going (more) insane over this... Cheers,
        /Fredrik

        Sonork ID: 100.11430:PhatBoy

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        FOrget about my first reply (it won't work). Best way is to store on some well known variable a pointer to the button that last issued the popmenu. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        1 Reply Last reply
        0
        • F Fredrik Skog

          E.g. I have a toolbar to which I can add buttons. Each button has a menu with two menu items: "Configure" and "Remove". The menu is displayed when the right mouse button is clicked on the button. The menu is a child of the toolbar, thus having the message routing taken care of in the toolbar. The question is, how can I tell which button the menu was invoked on, in order to know which button to remove when the user selects "Remove"? Is my design all wrong or what? I am going (more) insane over this... Cheers,
          /Fredrik

          Sonork ID: 100.11430:PhatBoy

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You can the id of the item selected by capturing the WM_MENUSELECT message.

          F 1 Reply Last reply
          0
          • N Not Active

            You can the id of the item selected by capturing the WM_MENUSELECT message.

            F Offline
            F Offline
            Fredrik Skog
            wrote on last edited by
            #5

            The menu is already working fine. What I need to know is which button that invoked the menu. The button has a OnRButtonDown handler which displays the menu. When the user selects an item in the menu the command handling is taken care of in the parent toolbar. How do I make the toolbar aware of which button it was that issued the menu? E.g. CDynamicButton.cpp

            void CDynamicButton::OnRButtonDown(UINT nFlags, CPoint point)
            {
            // Handle the menu (if any)
            if (m_hMenu)
            {
            HMENU hSubMenu = NULL;
            CRect rWnd;

            	hSubMenu = ::GetSubMenu(m\_hMenu, 0);
            	GetWindowRect(rWnd);
            	::TrackPopupMenuEx(hSubMenu, TPM\_LEFTALIGN | TPM\_LEFTBUTTON, rWnd.left, rWnd.bottom, m\_hParentWndMenu, NULL);
            } // if
            
            CButton::OnRButtonDown(nFlags, point);
            

            }

            CMacroToolBarCtrl.cpp:

            BEGIN_MESSAGE_MAP(CMacroToolBarCtrl, CDialogBar)
            ON_UPDATE_COMMAND_UI(ID_MENU_REMOVE, OnMenuRemove)
            END_MESSAGE_MAP()

            void CMacroToolBarCtrl::OnMenuRemove(CCmdUI* pCmdUI)
            {
            // Need to remove the button here
            }

            Cheers,
            /Fredrik

            Sonork ID: 100.11430:PhatBoy

            N 1 Reply Last reply
            0
            • F Fredrik Skog

              The menu is already working fine. What I need to know is which button that invoked the menu. The button has a OnRButtonDown handler which displays the menu. When the user selects an item in the menu the command handling is taken care of in the parent toolbar. How do I make the toolbar aware of which button it was that issued the menu? E.g. CDynamicButton.cpp

              void CDynamicButton::OnRButtonDown(UINT nFlags, CPoint point)
              {
              // Handle the menu (if any)
              if (m_hMenu)
              {
              HMENU hSubMenu = NULL;
              CRect rWnd;

              	hSubMenu = ::GetSubMenu(m\_hMenu, 0);
              	GetWindowRect(rWnd);
              	::TrackPopupMenuEx(hSubMenu, TPM\_LEFTALIGN | TPM\_LEFTBUTTON, rWnd.left, rWnd.bottom, m\_hParentWndMenu, NULL);
              } // if
              
              CButton::OnRButtonDown(nFlags, point);
              

              }

              CMacroToolBarCtrl.cpp:

              BEGIN_MESSAGE_MAP(CMacroToolBarCtrl, CDialogBar)
              ON_UPDATE_COMMAND_UI(ID_MENU_REMOVE, OnMenuRemove)
              END_MESSAGE_MAP()

              void CMacroToolBarCtrl::OnMenuRemove(CCmdUI* pCmdUI)
              {
              // Need to remove the button here
              }

              Cheers,
              /Fredrik

              Sonork ID: 100.11430:PhatBoy

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              (1) Use GetItemRect to get the RECTs of all the buttons in your toolbar. (2) In your OnRButtonDown you can get the CPoint of the area where the mouse was clicked (3) Now figure out from these two, where the mouse was clicked Regards Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

              F 2 Replies Last reply
              0
              • N Nish Nishant

                (1) Use GetItemRect to get the RECTs of all the buttons in your toolbar. (2) In your OnRButtonDown you can get the CPoint of the area where the mouse was clicked (3) Now figure out from these two, where the mouse was clicked Regards Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                F Offline
                F Offline
                Fredrik Skog
                wrote on last edited by
                #7

                Well, that works for a CToolBar, but I am using a CDialogBar. I think I have seen something somewhere about replacing original bitmap buttons in a CToolBar with all kinds of controls. Could this be an option? (I want to use my own button class with only text on) Cheers,
                /Fredrik

                Sonork ID: 100.11430:PhatBoy

                1 Reply Last reply
                0
                • N Nish Nishant

                  (1) Use GetItemRect to get the RECTs of all the buttons in your toolbar. (2) In your OnRButtonDown you can get the CPoint of the area where the mouse was clicked (3) Now figure out from these two, where the mouse was clicked Regards Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                  F Offline
                  F Offline
                  Fredrik Skog
                  wrote on last edited by
                  #8

                  Ok, I have solved it now. Thanks for pointing me in the right direction!:-D Cheers,
                  /Fredrik

                  Sonork ID: 100.11430:PhatBoy

                  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