Click here to Skip to main content
11,790,613 members (62,490 online)
Rate this: bad
Please Sign up or sign in to vote.
(Not really an urgent problem to fix).

I'm using a CMFToolbar with some custom buttons in them (edit box).

In the handler of AFX_WM_RESETTOOLBAR, I create and replace the toolbar button with a CMFCToolBarEditBoxButton .


LRESULT CMainFrame::OnToolbarReset(WPARAM wp,LPARAM)
  UINT uiToolBarId = (UINT) wp;
  if ( uiToolBarId == ID_MY_TOOLBAR)
    CMFCToolBarEditBoxButton edit(IDM_BUTTON, 
       GetCmdMgr()->GetCmdImage(IDM_BUTTON, FALSE), 
       ES_RIGHT, 75);
    m_DeviceToolBar.ReplaceButton(IDM_BUTTON, edit);

This works, and will create an edit box with a width of 75 in the toolbar.
This also works for other kind of controls in the toolbar.

But now, if I want to increase the width of the editbox to 100 (for example), I will change the code to

CMFCToolBarEditBoxButton edit(IDM_BUTTON,
   GetCmdMgr()->GetCmdImage(IDM_BUTTON, FALSE),
   ES_RIGHT, 100);

This will not automatically be reflected when the program is executed because the actual size is stored in the registry.

User either have to scrap the registry entry or go in the customize dialog and rest the toolbar.

Is there a clean built-in way to have the toolbar marked as "dirty" so that its settings will not be loaded from the registry (once) ?

I can think of many ways to hack that into place, but I feel it will cause more harm than necessary.

Posted 28-Nov-12 4:27am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just construct your own derivation with reimplemented compare-function:
class CMyEditButton : public CMFCToolBarEditBoxButton
  virtual BOOL CompareWith(const CMFCToolBarButton& other) const {
    return CMFCToolBarEditBoxButton::CompareWith(other) &&
           other.IsKindOf(RUNTIME_CLASS(CMyEditButton)) &&
           m_iWidth == other.m_iWidth;
}; will set the m_bResourceChanged flag of the parent Toolbar
and reset it (the bar) after its loading Smile | :)
Maximilien at 29-Nov-12 7:29am
Nice, will check that out when I get to work.

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

  Print Answers RSS
0 OriginalGriff 1,154
1 Maciej Los 825
2 KrunalRohit 686
3 ppolymorphe 660
4 CPallini 621

Advertise | Privacy | Mobile
Web03 | 2.8.1509028.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2015
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