Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
Hello
 
Env: Win 7 MS Visual Studio 11
 
I need to select a ribbon category programmatically ...
 
I use: pMainFrame->m_wndRibbonBar.SetActiveCategory( pMainFrame->m_wndRibbonBar.GetCategory( 3), TRUE);
and this is selecting the right ribbon (index 3, the fourth category of the ribbon) when I run the exe in XP....
 
But this code selects the second category ( index 2) when used in Windows 7 !!!
 
Any idea what is the right way to select a given ribbon category ?
 
Thanks for your help
 
Thierry
Posted 19-Nov-12 12:38pm

1 solution

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

Solution 1

Hello All
 
Problem Solved.... The trick is not to use the index but the name of the category...
 
Here is a function that do that:
 
int CYourClassName::ActivateCategoryByName( CString strCategoryName)
{
      // Grab Pointer to MainFrame 
	
  CMainFrame* pMainFrame = ( CMainFrame*) AfxGetMainWnd();
 
  // Grab Pointer to RibbonBar

  CMFCRibbonBar* pmrb = &pMainFrame->m_wndRibbonBar;
 
  // Get Category Count
		
  int nCategoryCount = pmrb->GetCategoryCount();
 
  // Scan Category

  for ( int nCategoryNdx = 0; nCategoryNdx < nCategoryCount; nCategoryNdx++)
  {
    // Grab Pointer to Category

    CMFCRibbonCategory* pmrc = pmrb->GetCategory( nCategoryNdx);
 
    // Get Category Name

    CString strName = pmrc->GetName();
 
    // Check for Requested Category

    if ( strName == strCategoryName)
    {
      pmrb->ShowCategory( nCategoryNdx, TRUE);
 
      pmrb->SetActiveCategory( pmrc, TRUE);		
 
      return nCategoryNdx;
    }
  }
 
  return -1;
}
 
Thierry
  Permalink  
v2
Comments
Hesam Gholami at 9-Sep-13 4:48am
   
I also have this problem,thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2014
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