Note that there are some explanatory texts on larger screens.

plurals
  1. POCMFCToolbar ReplaceButton() causes button to disappear
    primarykey
    data
    text
    <p>Using <strong>Visual Studio 2010</strong> and working with an <strong>MFC SDI Application</strong>. I have a <strong>CMFCToolbar</strong> object owned by the Main Frame. </p> <p>When the document in this application is created, the MainFrame calls a function to replace one of the buttons in the CMFCToolbar object with a <strong>CMFCToolbarMenuButton</strong>. The contents of the menu button are populated with information from the document. The menu creation always works. The call to ReplaceButton always succeeds. But there's a visual symptom of the call that I haven't yet figured out. </p> <p>Any time ReplaceButton is called, the button disappears. Not only is it not drawn, it's not clickable. It's temporarily gone. I assume this is because there's a dangling reference to the old button, which I have just destroyed with the call to ReplaceButton.</p> <p>I've tried calling Invalidate(), RecalcLayout() to trigger a re-draw, but neither has worked yet. The only reliable method I have for getting the button to show up is re-sizing the application window manually or by un-docking/re-docking the toolbar. I assume there's some kind of lower-level refresh that occurs in these situations, but I don't know how to trigger it manually.</p> <p>Is there a way to make sure my button is drawn immediately?</p> <p>Edit: code sample</p> <pre><code>Count = m_Doc-&gt;...-&gt;GetCount(); for (Index = 0; Index &lt; Count; ++Index) { Caption.Format(L"%s", m_Doc-&gt;...-&gt;GetName()); m_pLayerMenu-&gt;AppendMenu(MF_ENABLED | MF_STRING, LAYER_DROP_SEED+Index, Caption.GetData()); } m_wndBrushBar.ReplaceButton(ID_BRUSH_TERRAIN, CMFCToolBarMenuButton(ID_BRUSH_TERRAIN, *m_pLayerMenu, GetCmdMgr()-&gt;GetCmdImage(ID_BRUSH_TERRAIN))); </code></pre> <p>Update:</p> <p>Calling <code>m_wndBrushBar.AdjustLayout()</code> seems to stabilize the visual behavior of these CMFCToolbar buttons. So that's a partial solution. Partial because of the following:</p> <p>It's hard to tell what the real visual behavior is. It turns out that all visual settings/states are stored in the Registry with these MFC objects, and it can hold onto states of dynamically created objects that really alter the startup behavior of the app.</p> <p>I've gone in to delete the registry values under </p> <p><code>Current User -&gt; "Local App-Wizard Generated Applications" -&gt; [My App Name]</code>. Done this a number of times, just to find out what the real behavior of my app is. Feel like I'm missing some fundamental knowledge with the current version of MFC. Lots of bugs arising from the registry deal.</p> <p>Is there a way to prevent registry settings for certain objects, or to shut off this behavior altogether? Otherwise, I guess my shutdown process will have to be a LOT more thorough with resetting all the visual elements. Registry values seem to ignore, override, or bypass my startup code. I can code how I want an object to look at startup, but if there are values in the registry, it does no good.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload