Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Different icons for buttons with same ID in ribbon bar Collapse All
Subject Author Date
Robert Webb Nov 6, 2008 - 9:41 PM

Is there a way to display different icons (ie both large and small icons) on different ribbon bar buttons that share the same command ID?  Or are they forever tied to the command manager?


Currently as I create my ribbon bar buttons, when I create a new button with the same ID as an old one, the icon I specify filters back to the old button as well, even though I specified a different icon when I created it.


Thanks,

Rob.

Technical Support Nov 7, 2008 - 3:16 PM

Yes, you can initialize different icons while initializing command tree nodes. But there is no reason for that because two ribbon buttons with the same command identifier will be handled by one command handler method and updated by one command updating method.

Robert Webb Nov 11, 2008 - 8:22 PM

Sorry, I’m not sure how this answer relates to the question.


What I want is two ribbon bar buttons with the same ID, but each using a different icon.  Yes, both buttons will be handled by the same command handler, but they should maintain different icons.


Maybe this sounds like a strange request, but it makes sense in context.  I know I could use different IDs that lead to the same command handler, but there’s quite a lot of these to go through so I was hoping to avoid that.


Thanks,

Rob.

Technical Support Nov 13, 2008 - 12:22 PM

We modified the CMainFrame::_InitRibbonNode_Home_Clipboard() method in the RibbonBar sample:

CExtRibbonNode * CMainFrame::_InitRibbonNode_Home_Clipboard()
{
CExtRibbonNodeGroup * pRibbonGroup =
                        new CExtRibbonNodeGroup( ID_RIBBON_PAGE_CLIPBOARD );
            pRibbonGroup->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_LPCTSTR( _T("ZC") ) ), false );
            VERIFY( pRibbonGroup->m_iconBig.m_bmpNormal.LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) ) );
            pRibbonGroup->m_iconBig.m_bmpNormal.Make32();
            pRibbonGroup->m_iconBig.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    CExtCustomizeCmdScreenTip * pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->TextMainSet( _T("Clipboard") );
                                                                                    pRibbonGroup->CmdScreenTipAttach( pCmdScreenTip );
            pRibbonGroup->SetTextInToolbar( _T("Clipboard") );

CExtRibbonNodeDialogLauncher * pRibbonDLB =
                        new CExtRibbonNodeDialogLauncher( ID_RIBBON_PAGE_CLIPBOARD );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Clipboard") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Show the Clipboard\nTask Pane.") );
                                                                                    pCmdScreenTip->BmpMainGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_CLIPBOARD_DLB_TIP_IMAGE) );
                                                                                    pCmdScreenTip->BmpMainGet().Make32();
                                                                                    pCmdScreenTip->BmpMainGet().AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pRibbonDLB->CmdScreenTipAttach( pCmdScreenTip );
            pRibbonDLB->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_LPCTSTR( _T("FO") ) ), false );
            pRibbonGroup->InsertNode( NULL, pRibbonDLB );


//          pRibbonGroup->InsertNode( NULL, new CExtRibbonNodeDialogLauncher( ID_RIBBON_PAGE_CLIPBOARD ) );
//          pRibbonGroup->InsertNode( NULL, new CExtRibbonNodeDialogLauncher( ID_RIBBON_PAGE_CLIPBOARD ) );
//          pRibbonGroup->InsertNode( NULL, new CExtRibbonNodeDialogLauncher( ID_RIBBON_PAGE_CLIPBOARD ) );


// CExtRibbonNode * pNodePaste =
//                      new CExtRibbonNode( ID_EDIT_PASTE, 0, NULL, 0, _T("Paste") );
//          pNodePaste->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’V’) ) ), false );
//          pNodePaste->RibbonILE_RuleArrayGet().RemoveAll();
//          VERIFY( pNodePaste->m_iconBig.m_bmpNormal.LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) ) );
//          pNodePaste->m_iconBig.m_bmpNormal.Make32();
//          pNodePaste->m_iconBig.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
//                                                                                  pCmdScreenTip = new CExtCustomizeCmdScreenTip;
//                                                                                  pCmdScreenTip->CaptionMainSet( _T("Paste") );
//                                                                                  pCmdScreenTip->TextMainSet( _T("Paste the contents\nof the Clipboard.") );
//                                                                                  pCmdScreenTip->BmpMainGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) );
//                                                                                  pCmdScreenTip->BmpMainGet().Make32();
//                                                                                  pCmdScreenTip->BmpMainGet().AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
//                                                                                  pCmdScreenTip->CaptionSecondarySet( _T("Press F1 for more help.") );
//                                                                                  pCmdScreenTip->BmpSecondaryGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_APP_ABOUT_16x16) );
//                                                                                  pCmdScreenTip->BmpSecondaryGet().PreMultiplyRGBChannels( false );
//                                                                                  pNodePaste->CmdScreenTipAttach( pCmdScreenTip );
//                                                                                  pCmdScreenTip = new CExtCustomizeCmdScreenTip;
//                                                                                  pCmdScreenTip->CaptionMainSet( _T("Paste") );
//                                                                                  pCmdScreenTip->TextMainSet( _T("Click here for more options such as\npasting only the values or\nformatting.") );
//                                                                                  pCmdScreenTip->BmpMainGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) );
//                                                                                  pCmdScreenTip->BmpMainGet().Make32();
//                                                                                  pCmdScreenTip->BmpMainGet().AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
//                                                                                  pCmdScreenTip->CaptionSecondarySet( _T("Press F1 for more help.") );
//                                                                                  pCmdScreenTip->BmpSecondaryGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_APP_ABOUT_16x16) );
//                                                                                  pCmdScreenTip->BmpSecondaryGet().PreMultiplyRGBChannels( false );
//                                                                                  pNodePaste->CmdScreenTipAttach( pCmdScreenTip, false );
//          pRibbonGroup->InsertNode(
//                      NULL,
//                      pNodePaste
//                      );

CExtRibbonNode * pNodePaste1 =
                        new CExtRibbonNode( ID_EDIT_PASTE, 0, NULL, 0, _T("Paste") );
            pNodePaste1->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’V’) ) ), false );
            pNodePaste1->RibbonILE_RuleArrayGet().RemoveAll();
            VERIFY( pNodePaste1->m_iconBig.m_bmpNormal.LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) ) );
            pNodePaste1->m_iconBig.m_bmpNormal.Make32();
            pNodePaste1->m_iconBig.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Paste") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Paste the contents\nof the Clipboard.") );
                                                                                    pCmdScreenTip->BmpMainGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) );
                                                                                    pCmdScreenTip->BmpMainGet().Make32();
                                                                                    pCmdScreenTip->BmpMainGet().AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip->CaptionSecondarySet( _T("Press F1 for more help.") );
                                                                                    pCmdScreenTip->BmpSecondaryGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_APP_ABOUT_16x16) );
                                                                                    pCmdScreenTip->BmpSecondaryGet().PreMultiplyRGBChannels( false );
                                                                                    pNodePaste1->CmdScreenTipAttach( pCmdScreenTip );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Paste") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Click here for more options such as\npasting only the values or\nformatting.") );
                                                                                    pCmdScreenTip->BmpMainGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) );
                                                                                    pCmdScreenTip->BmpMainGet().Make32();
                                                                                    pCmdScreenTip->BmpMainGet().AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip->CaptionSecondarySet( _T("Press F1 for more help.") );
                                                                                    pCmdScreenTip->BmpSecondaryGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_APP_ABOUT_16x16) );
                                                                                    pCmdScreenTip->BmpSecondaryGet().PreMultiplyRGBChannels( false );
                                                                                    pNodePaste1->CmdScreenTipAttach( pCmdScreenTip, false );
            pRibbonGroup->InsertNode(
                        NULL,
                        pNodePaste1
                        );

CExtRibbonNode * pNodePaste2 =
                        new CExtRibbonNode( ID_EDIT_PASTE, 0, NULL, 0, _T("Paste") );
            pNodePaste2->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’V’) ) ), false );
            pNodePaste2->RibbonILE_RuleArrayGet().RemoveAll();
            VERIFY( pNodePaste2->m_iconBig.m_bmpNormal.LoadBMP_Resource( MAKEINTRESOURCE(ID_QUICK_STYLES_BIG) ) );
            pNodePaste2->m_iconBig.m_bmpNormal.Make32();
            pNodePaste2->m_iconBig.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Paste") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Paste the contents\nof the Clipboard.") );
                                                                                    pCmdScreenTip->BmpMainGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_QUICK_STYLES_BIG) );
                                                                                    pCmdScreenTip->BmpMainGet().Make32();
                                                                                    pCmdScreenTip->BmpMainGet().AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip->CaptionSecondarySet( _T("Press F1 for more help.") );
                                                                                    pCmdScreenTip->BmpSecondaryGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_APP_ABOUT_16x16) );
                                                                                    pCmdScreenTip->BmpSecondaryGet().PreMultiplyRGBChannels( false );
                                                                                    pNodePaste2->CmdScreenTipAttach( pCmdScreenTip );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Paste") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Click here for more options such as\npasting only the values or\nformatting.") );
                                                                                    pCmdScreenTip->BmpMainGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_PASTE_BIG) );
                                                                                    pCmdScreenTip->BmpMainGet().Make32();
                                                                                    pCmdScreenTip->BmpMainGet().AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip->CaptionSecondarySet( _T("Press F1 for more help.") );
                                                                                    pCmdScreenTip->BmpSecondaryGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_APP_ABOUT_16x16) );
                                                                                    pCmdScreenTip->BmpSecondaryGet().PreMultiplyRGBChannels( false );
                                                                                    pNodePaste2->CmdScreenTipAttach( pCmdScreenTip, false );
            pRibbonGroup->InsertNode(
                        NULL,
                        pNodePaste2
                        );

//          g_CmdManager->CmdAllocPtr(
//                      g_CmdManager->ProfileNameFromWnd( m_hWnd ),
//                      ID_EDIT_PASTE )->m_sMenuText = "12";

// pNodePaste->ModifyFlags( __ECTN_TBB_SEPARATED_DROPDOWN );
//                                  CExtCustomizeCmdTreeNode * pNodePaste_Paste =
//                                              new CExtCustomizeCmdTreeNode( ID_EDIT_PASTE, ID_EDIT_PASTE, NULL, 0, _T("Paste"), _T("&Paste") );
//                                  pNodePaste_Paste->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’P’) ) ), false );
//                                  pNodePaste->InsertNode(
//                                              NULL,
//                                              pNodePaste_Paste
//                                              );
// 
//                                  CExtCustomizeCmdTreeNode * pNodePaste_Special =
//                                              new CExtCustomizeCmdTreeNode( ID_EDIT_PASTE_SPECIAL, ID_EDIT_PASTE_SPECIAL, NULL, 0, _T("Paste &Special...") );
//                                  pNodePaste_Special->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’S’) ) ), false );
//                                  pNodePaste->InsertNode(
//                                              NULL,
//                                              pNodePaste_Special
//                                              );
// 
//                                  CExtCustomizeCmdTreeNode * pNodePaste_Hyperlink =
//                                              new CExtCustomizeCmdTreeNode( ID_EDIT_PASTE_AS_HYPERLINK, ID_EDIT_PASTE_AS_HYPERLINK, NULL, 0, _T("Paste as &Hyperlink") );
//                                  pNodePaste_Hyperlink->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’H’) ) ), false );
//                                  pNodePaste->InsertNode(
//                                              NULL,
//                                              pNodePaste_Hyperlink
//                                              );

//          pRibbonGroup->InsertNode(
//                      NULL,
//                      new CExtRibbonNode // separator
//                      );

CExtRibbonNode * pNodeCopy =
                        new CExtRibbonNode( ID_EDIT_COPY, 0, NULL, 0, _T("Copy") );
            pNodeCopy->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’C’) ) ), false );
//pNodeCopy->ModifyFlags( __ECTN_TBB_UNDO_REDO|__ECTN_TBB_SEPARATED_DROPDOWN );
            pNodeCopy->RibbonILE_RuleRemoveLargeILV();
            VERIFY( pNodeCopy->m_iconSmall.m_bmpNormal.LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_COPY_SMALL) ) );
            pNodeCopy->m_iconSmall.m_bmpNormal.Make32();
            pNodeCopy->m_iconSmall.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Copy") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Copy the selection and\nput it on the Clipboard.") );
                                                                                    pNodeCopy->CmdScreenTipAttach( pCmdScreenTip );
            pRibbonGroup->InsertNode(
                        NULL,
                        pNodeCopy
                        );

CExtRibbonNode * pNodeCut =
                        new CExtRibbonNode( ID_EDIT_CUT, 0, NULL, 0, _T("Cut") );
            pNodeCut->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’X’) ) ), false );
            pNodeCut->RibbonILE_RuleRemoveLargeILV();
            VERIFY( pNodeCut->m_iconSmall.m_bmpNormal.LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_CUT_SMALL) ) );
            pNodeCut->m_iconSmall.m_bmpNormal.Make32();
            pNodeCut->m_iconSmall.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Cut") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Cut the selection from the document\nand put it on the Clipboard.") );
                                                                                    pNodeCut->CmdScreenTipAttach( pCmdScreenTip );
            pRibbonGroup->InsertNode(
                        NULL,
                        pNodeCut
                        );

CExtRibbonNode * pNodeClearFormatting =
                        new CExtRibbonNode( ID_EDIT_CLEAR, 0, NULL, 0, _T("Clear Formatting") );
            pNodeClearFormatting->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_LPCTSTR( _T("FP") ) ), false );
            pNodeClearFormatting->RibbonILE_RuleRemoveLargeILV();
            VERIFY( pNodeClearFormatting->m_iconSmall.m_bmpNormal.LoadBMP_Resource( MAKEINTRESOURCE(ID_EDIT_CLEAR_SMALL) ) );
            pNodeClearFormatting->m_iconSmall.m_bmpNormal.Make32();
            pNodeClearFormatting->m_iconSmall.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), 0 );
                                                                                    pCmdScreenTip = new CExtCustomizeCmdScreenTip;
                                                                                    pCmdScreenTip->CaptionMainSet( _T("Clear Formatting") );
                                                                                    pCmdScreenTip->TextMainSet( _T("Copy the formatting from one place\nand apply it to an other.\n\nUse this button to apply\nthe same formatting to multiple\nplaces in the document.") );
                                                                                    pCmdScreenTip->CaptionSecondarySet( _T("Press F1 for more help.") );
                                                                                    pCmdScreenTip->BmpSecondaryGet().LoadBMP_Resource( MAKEINTRESOURCE(ID_APP_ABOUT_16x16) );
                                                                                    pCmdScreenTip->BmpSecondaryGet().PreMultiplyRGBChannels( false );
                                                                                    pNodeClearFormatting->CmdScreenTipAttach( pCmdScreenTip );
            pRibbonGroup->InsertNode(
                        NULL,
                        pNodeClearFormatting
                        );

            return pRibbonGroup;
}
We commented out initialization of the pNodePaste node in the original method. We added the pNodePaste1 and pNodePaste2 nodes instead and both of them have the same ID_EDIT_PASTE identifier and different icons. We simply used different icons and equal identifiers. There are no other specific things required.