Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I've followed all the instructions I can find online on how to customise a toolbar by calling CMFCToolBar::ReplaceButton(), and have got it to display a CMFCToolBarComboBoxButton.

I have subclassed CMFCToolBarComboBoxButton in order to override CreateCombo(), but if I call CMFCToolBar::ReplaceButton() with this derived class, my derived CreateCombo() is never being called.

Any ideas what I am doing wrong?

TIA.

PS - This project was converted from VS2005 to VS2010, if that makes any difference.
Posted
Updated 20-Jun-12 4:52am
v2

// I get a pointer to a CMFCToolBarComboBoxButton, not to my derived class

Just place DECLARE_DYNCREATE(CYourButton) into its declaration :)
 
Share this answer
 
Comments
hairy_hats 20-Jun-12 10:58am    
That's got it! Thanks Eugen! :D
Maximilien 20-Jun-12 11:16am    
Yes. forgot about that.
Maximilien 20-Jun-12 14:48pm    
just a brain freeze question, is it IMPLEMENT/DECLARE_DYNCREATE or IMPLEMENT/DECLARE_SERIAL ?
the doc on MSDN says to use IMPLEMENT_SERIAL : http://msdn.microsoft.com/en-us/library/bb983718.aspx
Eugen Podsypalnikov 21-Jun-12 1:50am    
Hi Maximilien ! Yes, you will need IMPLEMENT_SERIAL instead, if your button has own persistent members and must be serialized dynamically by the framework, of course ! :)
Where (what method) do you call Replace Button.


It should be done in the handler of AFX_WM_RESETTOOLBAR in the main frame.

this is what I do:
...
ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)
...
C++
LRESULT CMainFrame::OnToolbarReset(WPARAM wp,LPARAM)
{
 UINT uiToolBarId = (UINT) wp;
 TRACE( "CMainFrame::OnToolbarReset : %i\n", uiToolBarId );

 switch (uiToolBarId)
 {
  case YOUR_TOOLBAR_ID:
    CMFCToolBarComboBoxButton deviceCombo(IDC_DEVICE_TOOLBAR_COMBO, GetCmdMgr()->GetCmdImage(IDC_DEVICE_TOOLBAR_COMBO, FALSE), CBS_DROPDOWNLIST);
    m_DeviceToolBar.ReplaceButton ( IDC_DEVICE_TOOLBAR_COMBO, deviceCombo   );

  break;
 }
}


NOTE: the framework will save/load the state of the buttons of the toolbars in the registry, if you make changes to the code, the application will still use those values. so remove your application entry in the registry when (re)coding toolbars. This is quite aggravating.

Good luck.
 
Share this answer
 
Comments
hairy_hats 20-Jun-12 10:48am    
That's what I do, but with a derived button, as described here. If I get a pointer to this replaced button via CMFCToolBar::GetCommandButtons(), I get a pointer to a CMFCToolBarComboBoxButton, not to my derived class. I deleted the Registry entries so that they were regenerated with the new class.
Gbenbam 28-Feb-17 8:25am    
I am working on this same thing. How does one locate the registry entry?
i have implemented CMFCToolbarComboboxbutton in Menubar.
and i also specified a Label text for it.
but it does not show label.
so
how to set label for CMFCToolbarComboboxbutton in Menubar?
plz help me
 
Share this answer
 
Comments
hairy_hats 25-Oct-13 6:56am    
Have you tried deleting the corresponding Registry data for your program? Sometimes changes to the UI don't show up if you change something without deleting the Registry data, as Maximilien said above.
Gbenbam 28-Feb-17 8:25am    
I am working on this same thing. How does one locate the registry entry?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900