Home Dashboard Directory Help

CMFCRibbonBar::AddToTabs removes a wrong button from the m_arButtons array by jasmin42


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 757588
Opened: 8/9/2012 3:08:57 AM
Access Restriction: Public
User(s) can reproduce this bug


Seen on Visual Studio 2012RC AND also Visual Studio 2010.

When a new button is added to a CMFCRibbonBar (CMFCRibbonBar::AddToTabs function) including System buttons, the new button is first added to the m_arButton then moved before the system buttons.
In this function, the local variable "nSize" is decremented twice, then a wrong button (generally the close button) is removed instead of the new added button.

void CMFCRibbonBar::AddToTabs(CMFCRibbonBaseElement* pElement)


if (m_nSystemButtonsNum > 0)
    // Move the new lement prior to system buttons:
    int nSize = (int) m_TabElements.m_arButtons.GetSize() - 1;

HERE ==>    m_TabElements.m_arButtons.RemoveAt(nSize - 1);
    m_TabElements.m_arButtons.InsertAt(nSize - m_nSystemButtonsNum, pElement);
Sign in to post a comment.
Posted by jasmin42 on 4/11/2013 at 1:08 AM
Not yet solved in the last VS2012 Update 2 (11.0.60315.01)
Posted by jasmin42 on 8/13/2012 at 11:14 AM
Please read ' "Close" button ' instead of ' "Code" bouton' in my comment below
Posted by Microsoft on 8/13/2012 at 1:38 AM
Thanks for your update. We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by jasmin42 on 8/10/2012 at 4:34 AM
Don't forget to maximize the MDI Window. The "Code" button will be missing and when the MDI windows will be restored or the application closed, the App will crash.
Posted by jasmin42 on 8/10/2012 at 12:43 AM
Here is a sample that create the failure. Create a default project with no tabs and a ribbon then add an handler for WM_SIZE to CChildFrame class. I also attached the entire project.

#include "MainFrm.h"
void CChildFrame::OnSize(UINT nType, int cx, int cy)
CMDIChildWndEx::OnSize(nType, cx, cy);

// TODO: ajoutez ici le code de votre gestionnaire de messages
static int nCount = 0;
if ((nType == SIZE_MAXIMIZED) && (nCount++ == 0))
    CMFCRibbonButton *pElement = new CMFCRibbonButton(1234, _T("Text"), 1);
Posted by Microsoft on 8/9/2012 at 7:27 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

Please submit this information to us within 4 business days. We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 8/9/2012 at 3:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
TestAddToTabs.zip 8/10/2012 163 KB