以编程方式选择功能区类别 [英] Programmatically Select Ribbon Category

查看:69
本文介绍了以编程方式选择功能区类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



环境:赢7 MS Visual Studio 11



我需要选择一条色带类别编程...



我使用:pMainFrame-> m_wndRibbonBar.SetActiveCategory(pMainFrame-> m_wndRibbonBar.GetCategory(3),TRUE);

这是我在XP中运行exe时选择正确的功能区(索引3,功能区的第四类)....



但是在Windows 7中使用时,此代码选择第二个类别(索引2)!!!



任何想法选择给定功能区类别的正确方法是什么?



感谢您的帮助



Thierry

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

推荐答案

Hello All



解决问题 ....诀窍不是使用索引而是使用类别的名称。 ..



这是一个功能:



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



Thierry


这篇关于以编程方式选择功能区类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆