Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
(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 .

ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)

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

C++
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.

Thanks.
Posted

1 solution

Just construct your own derivation with reimplemented compare-function:
C++
class CMyEditButton : public CMFCToolBarEditBoxButton
{
  DECLARE_SERIAL(CMyEditButton)
//..
public:
//..
  virtual BOOL CompareWith(const CMFCToolBarButton& other) const {
    return CMFCToolBarEditBoxButton::CompareWith(other) &&
           other.IsKindOf(RUNTIME_CLASS(CMyEditButton)) &&
           m_iWidth == other.m_iWidth;
  }
//..
};

...it will set the m_bResourceChanged flag of the parent Toolbar
and reset it (the bar) after its loading :)
 
Share this answer
 
v2
Comments
Maximilien 29-Nov-12 7:29am    
Nice, will check that out when I get to work.
Thanks

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