问题描述
你好
环境:赢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
推荐答案
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
这篇关于以编程方式选择功能区类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!