Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Attaching menu to CExtToolControlBar button Collapse All
Subject Author Date
Leon Miller Feb 13, 2006 - 7:39 PM

I understand how to attach a menu to a CExtToolControlBar button:

INT nBtnIdx = m_wndViewBar.CommandToIndex(ID_MYBUTTON );
CMenu _menu.LoadMenu(IDR_MAINFRAME);
m_wndToolBar.SetButtonMenu(nBtnIdx, _menu.Detach());

IDR_MAINFRAME is the standard menu File, View, etc....
The above works fine - the File menu items are assigned to the button, but what I’d like to do is assign the View menu items to the button.

I have tried this:

INT nBtnIdx = m_wndViewBar.CommandToIndex(ID_MYBUTTON );
CMenu _menu.LoadMenu(IDR_MAINFRAME);
CMenu *pSubMenu = _menu.GetSubMenu(1);
m_wndToolBar.SetButtonMenu(nBtnIdx, pSubMenu->Detach());

code compiles, but crashes at runtime (debug assertion, ExtPopupMenuWnd.cpp, line 7432) when the button is selected... any ideas?

Win XP/VC 7/ProfUIS 2.50



Technical Support Feb 14, 2006 - 10:11 AM

The _menu variable is placed on the stack and it is destroyed when leaving the scope. So, you need to declare this variable as global (i.e. as a class member) or change the code.

Leon Miller Feb 17, 2006 - 8:28 PM

Same symptoms..after trying with the _menu variable global scope && as a class member..
Looking back at the code in my first post.... the code works fine for the first example in my previous post - even though the _menu variable does *not* have global scope. So I don’t believe scope is a problem here...

Technical Support Feb 18, 2006 - 8:33 AM

Moving the menu to the global scope delays its destruction up to app shutdown instead of end of the method. This makes its submenu available for a toolbar button. Your first code snippet detaches the menu handle from C++ class before putting it into the toolbar button and that is why the first variant works. You can use the first variant but you simply need to create a new menu resource which contains only items which should be displayed in toolbar button’s menu.