Message handling/command routing
-
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,
/FredrikSonork ID: 100.11430:PhatBoy
-
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,
/FredrikSonork ID: 100.11430:PhatBoy
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 -
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,
/FredrikSonork ID: 100.11430:PhatBoy
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
-
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,
/FredrikSonork ID: 100.11430:PhatBoy
You can the id of the item selected by capturing the WM_MENUSELECT message.
-
You can the id of the item selected by capturing the WM_MENUSELECT message.
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,
/FredrikSonork ID: 100.11430:PhatBoy
-
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,
/FredrikSonork ID: 100.11430:PhatBoy
(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
-
(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
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,
/FredrikSonork ID: 100.11430:PhatBoy
-
(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
Ok, I have solved it now. Thanks for pointing me in the right direction!:-D Cheers,
/FredrikSonork ID: 100.11430:PhatBoy