Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC VS2010
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 20-Jun-12 4:44am
viaducting91.5K
Edited 20-Jun-12 5:52am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

// I get a pointer to a CMFCToolBarComboBoxButton, not to my derived class
 
Just place DECLARE_DYNCREATE(CYourButton) into its declaration Smile | :)
  Permalink  
Comments
viaducting at 20-Jun-12 10:58am
   
That's got it! Thanks Eugen! :D
Maximilien at 20-Jun-12 11:16am
   
Yes. forgot about that.
Maximilien at 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 at 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 ! :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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)
...
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.
  Permalink  
Comments
viaducting at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Comments
viaducting at 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.

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 25 Oct 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100