Click here to Skip to main content
11,569,923 members (56,948 online)
Rate this: bad
good
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 .

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

    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 28-Nov-12 4:27am
Maximilien76.6K

1 solution

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

Solution 1

Just construct your own derivation with reimplemented compare-function:
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 Smile | :)
  Permalink  
v2
Comments
Maximilien at 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)

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | 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