If you have only a 32x32 icon, then you can create a very smoothly resized 16x16 version of this icon using highest quality resizing algorithms provided by the CExtBitmap
class and not based on Win32 API. Here is the part of the CMainFrame::_InitRibbonNode_Home_Clipboard()
method in the RibbonBar sample application which initializes the always big Paste ribbon button and loads the 32x32 ID_EDIT_PASTE_BIG
bitmap icon into it:
. . .
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 );
. . .
We can change this code and enable small icon state of this button without creating the 16x16 icon for it:
CExtRibbonNode * pNodePaste =
new CExtRibbonNode( ID_EDIT_PASTE, 0, NULL, 0, _T("Paste") );
pNodePaste->CmdKeyTipSet( new CExtCustomizeCmdKeyTip( __EXT_MFC_SAFE_TCHAR( _T(’V’) ) ), false );
// THIS LINE WAS COMMENTED: it disables all the button states excepting big state with 32x32 icon
// pNodePaste->RibbonILE_RuleArrayGet().RemoveAll();
// THIS LINE WAS COMMENTED =======================================================================
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 );
// THESE LINES WERE ADDED: creation of 16x16 icon from already loaded 32x32 icon =================
pNodePaste->m_iconSmall = pNodePaste->m_iconBig; // copy image surface
CExtBitmap::Filter _filter( CExtBitmap::Filter::lanczos ); // use extremely smooth scaling
pNodePaste->m_iconSmall.m_bmpNormal.Scale( 16, 16, _filter ); // do bitmap scaling
// THESE LINES WERE ADDED ========================================================================
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
);