MS功能区:从代码中绘制按钮图标
MS Ribbon: draw button icon from code
我尝试创建MS Ribbon按钮图标表单代码。我创建了32 bpp的CImage。
CImage img;
img.Create(size, size, 32, CImage::createAlphaChannel);
然后我用这个图像像hdc位图:
HDC hdc = CImageDC(img);
BitBlt(hdc, 0, 0, cx, cy, hdcMem, sx, sy, SRCCOPY);
最后,我使用UIRibbonImageFromBitmapFactory并将结果设置为属性:
IUIImage* pImg;
CComPtr<IUIImageFromBitmap> pifb;
pifb.CoCreateInstance(CLSID_UIRibbonImageFromBitmapFactory);
pifb->CreateImage(img, UI_OWNERSHIP_TRANSFER, &pImg);
UIInitPropertyFromImage(key, pImg, ppropvarNewValue);
结果所有功能都成功完成,但按钮图标为空!!!
我使用了这些要求http://msdn.microsoft.com/en-us/library/windows/desktop/dd316921(v=vs.85).aspx按钮图标是否需要其他要求?
您必须首先转换为HBITMAP,然后使用框架的工厂来生成IUIImage:
// Load the bitmap from the resource file.
CImage img;
hr = img.Load(pszResource);
if (FAILED(hr)) return hr;
HBITMAP hbm = (HBITMAP) img.Detach();
if (hbm)
{
// Use the factory implemented by the framework to produce an IUIImage.
hr = m_pifbFactory->CreateImage(hbm, UI_OWNERSHIP_TRANSFER, ppimg);
if (FAILED(hr))
{
DeleteObject(hbm);
}
}
然后您可以将图像添加到按钮中,如中所示
// Set the image as the new property value for the button.
hr = UIInitPropertyFromImage(UI_PKEY_LargeImage, pImg, ppropvarNewValue);
祝你好运!
相关文章:
- 问:如何使用C++中的按钮从窗口打开窗口
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- QML按钮点击功能执行顺序
- 当用户超过按钮点击限制时报告
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- QTool按钮上的文本未绘制
- 所有者绘制按钮的悬停效果
- 通过MQL4在MT4中启用趋势线绘制按钮
- 如何使用OpenGL在中心的按钮上绘制正方形
- 通过按住 Shift 按钮绘制直线的算法
- MS功能区:从代码中绘制按钮图标
- 使用DrawFrameControl绘制主题按钮
- 通过按住鼠标按钮绘制SDL/c++
- WIN32API:当点击时,所有者绘制的按钮会在文本周围创建白色背景
- WinApi:如何为屏幕阅读器的所有者绘制的按钮添加替代文本
- 如何使用按钮单击绘制 - C++ Windows 窗体
- 所有者绘制按钮强制刷新
- 如何在Qt中绘制关闭,最小化和最大化按钮