重载CMFCRibbonButton

由 Oliver Nie?lein 在 2012/5/24 0:49 发送
Hello,

To be perfect the DrawImage-Method should look like this:

virtual void DrawImage (CDC* pDC, RibbonImageType type, CRect rectImage)
{
    ASSERT_VALID (this);
    ASSERT_VALID (pDC);

    if (type != RibbonImageSmall || m_hIconSmall == NULL)
    {
        return;
    }

    CSize sizeIcon = GetImageSize(type);

    if (m_bIsDisabled)
    {
        CMFCToolBarImages icon;

        icon.AddIcon(m_hIconSmall, m_bAlphaBlendIcon);

        CAfxDrawState ds;
        icon.PrepareDrawImage(ds, sizeIcon);
        icon.Draw(pDC, rectImage.left, rectImage.top, 0, FALSE, TRUE);
        icon.EndDrawImage(ds);
    }
    else
    {
        ::DrawIconEx (pDC->GetSafeHdc (), rectImage.left, rectImage.top, m_hIconSmall, sizeIcon.cx, sizeIcon.cy, 0, NULL, DI_NORMAL);
    }
};

to support bluring out disabled icons...

Greetings from Germany,

Oliver Nie?lein
由 Microsoft 在 2011/1/17 14:23 发送
Hello,

Thanks for the report. As we have mentioned before, we consider this by design. Using an icon with a 16x16 image and without a 32x32 image is a rare case and we don't support it by design. Adding support at this point could cause compatibility issues with other MFC applications.

However, if for some reason you need to use an icon instead of a standard ribbon image list, there is a way to derive a button as described below:

class CIconButton : public CMFCRibbonButton
{
public:
CIconButton (UINT nID, LPCTSTR lpszText, HICON hIcon) :
CMFCRibbonButton(nID, lpszText, NULL, FALSE, hIcon)
{
}

virtual CSize GetImageSize (RibbonImageType type) const
{
if (type == RibbonImageLarge || m_hIconSmall == NULL)
{
return CSize(0, 0);
}

CSize sizeIcon(16, 16);

if (afxGlobalData.GetRibbonImageScale () != 1.)
{
sizeIcon.cx = (int) (.5 + afxGlobalData.GetRibbonImageScale () * sizeIcon.cx);
sizeIcon.cy = (int) (.5 + afxGlobalData.GetRibbonImageScale () * sizeIcon.cy);
}

return sizeIcon;
}

virtual void DrawImage (CDC* pDC, RibbonImageType type, CRect rectImage)
{
ASSERT_VALID (this);
ASSERT_VALID (pDC);

if (type != RibbonImageSmall || m_hIconSmall == NULL)
{
return;
}

CSize sizeIcon = GetImageSize(type);
::DrawIconEx (pDC->GetSafeHdc (), rectImage.left, rectImage.top, m_hIconSmall, sizeIcon.cx, sizeIcon.cy, 0, NULL, DI_NORMAL);
}
};

Then use this class instead of CMFCRibbonButton in your application:

//Create buttons
CIconButton* pButtonA = new CIconButton(ID_APP_ABOUT, L"A", hIconA);
CIconButton* pButtonB = new CIconButton(ID_APP_ABOUT, L"B", hIconB);
CIconButton* pButtonC = new CIconButton(ID_APP_ABOUT, L"B", hIconC);

I hope this helps in your scenario.

Pat Brenner
Visual C++ Libraries Development

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值