重载CMFCRibbonButton
来源:互联网 发布:淘宝10元麦克风 编辑:程序博客网 时间:2024/05/21 15:38
由 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
- 重载CMFCRibbonButton
- CButton & CMFCRibbonButton
- CMFCRibbonButton 变为Disable
- CMFCRibbonButton使用HICON作为参数的构造函数BUG
- 重载<<
- 重载
- 重载
- 重载
- 重载
- 重载()
- 重载
- 重载
- 重载
- 重载
- 重载
- “+ - * /”重载
- 重载
- 重载
- 简单读取带有EXCEL宏病毒文件的内容
- (十一)开创自己的数据类型:类的开始
- SQL学习快速链接
- android surfaceflinger
- SYBASE & ORACLE自增主键
- 重载CMFCRibbonButton
- 初学Android,监控ContentProvider的数据改变(五十七)
- Linux文件系统之文件的读写
- C#中判断是否为数字
- makefile自动化编译学习
- bucket and shared pool的深入探讨(一 基础)
- jslt Can not find the tag library descriptor for "http://java.sun.com/j...
- 李开复的时间管理建议
- HDU 1083 二分匹配