Using Visual Studio 2010 and working with the MFC SDI Application . I have a CMFCToolbar object belonging to the main frame.
When a document in this application is created, MainFrame calls a function to replace one of the buttons in the CMFCToolbar object using CMFCToolbarMenuButton . The content of the menu button is filled with information from the document. Creating a menu always works. The call to ReplaceButton always succeeds. But there is a visual symptom of a call that I have not yet understood.
When you call ReplaceButton, the button disappears. Not only is it not drawn, it is not accessible for clicks. It has temporarily disappeared. I assume this is due to the fact that there is a link to the old button that I just destroyed when I called ReplaceButton.
I tried calling Invalidate (), RecalcLayout () to trigger a re-draw, but it still doesn't work. The only reliable method I can get to display the button is to resize the application window manually or by removing the docking / re-docking of the toolbar. I assume there is something like a lower level update that happens in these situations, but I don't know how to start it manually.
Is there any way to make sure my button is drawn right away?
Edit: sample code
Count = m_Doc->...->GetCount(); for (Index = 0; Index < Count; ++Index) { Caption.Format(L"%s", m_Doc->...->GetName()); m_pLayerMenu->AppendMenu(MF_ENABLED | MF_STRING, LAYER_DROP_SEED+Index, Caption.GetData()); } m_wndBrushBar.ReplaceButton(ID_BRUSH_TERRAIN, CMFCToolBarMenuButton(ID_BRUSH_TERRAIN, *m_pLayerMenu, GetCmdMgr()->GetCmdImage(ID_BRUSH_TERRAIN)));
Update:
Calling m_wndBrushBar.AdjustLayout() seems to stabilize the visual behavior of these CMFCToolbar buttons. So a partial solution. Partly due to the following:
It is hard to say what real visual behavior is. It turns out that all visual settings / states are stored in the registry with these MFC objects and can contain the states of dynamically created objects that really change the behavior when the application starts.
I came to remove registry values ββin
Current User -> "Local App-Wizard Generated Applications" -> [My App Name] . This has been done several times, just to find out what the real behavior of my application is. Feel that I am lacking the fundamental knowledge in the current version of MFC. A lot of errors arising from a transaction with the registry.
Is there a way to prevent registry settings for specific objects or to disable this behavior altogether? Otherwise, I think my stopping process should be LOT more thorough with resetting all visual elements. The registry values ββseem to ignore, override, or bypass my startup code. I can specify how I want the object to look at startup, but if there are values ββin the registry, it does not mean anything.