我找到了这个link,它向您展示了如何将CBitmap
转换为HICON
:
HICON HICONFromCBitmap(CBitmap& bitmap)
{
BITMAP bmp;
bitmap.GetBitmap(&bmp);
HBITMAP hbmMask = ::CreateCompatibleBitmap(::GetDC(NULL),
bmp.bmWidth, bmp.bmHeight);
ICONINFO ii = {0};
ii.fIcon = TRUE;
ii.hbmColor = bitmap;
ii.hbmMask = hbmMask;
HICON hIcon = ::CreateIconIndirect(&ii);
::DeleteObject(hbmMask);
return hIcon;
}
所以我在我的应用程序中尝试了这个:
HICON hIcon = HICONFromCBitmap(m_mapMenuBitmap[5]);
VERIFY(hIcon);
m_StatusBar.GetStatusBarCtrl().SetIcon(paneProgressOrZoomFactor, hIcon);
有用:
在我的窗口期间,
hIcon
是否需要保持 Activity 状态?而且我必须释放它吗?为了澄清起见,我的
m_mapMeniBitmaps
是CBitmap
对象的映射,并且它们确实仍然存在。
最佳答案
在窗口期间,hIcon是否需要还活着?而且我必须释放它吗?
是的,是的!从documentation for CreateIconIndirect
(爆炸中的我):
When you are finished using the icon, destroy it using the DestroyIcon function.
我的
m_mapMenuBitmaps
是CBitmap
对象的映射,它们确实保持 Activity 状态。您可以在创建图标后释放这些
CBitmap
对象,但是,如您所正确记述的那样,它们仍保持“ Activity ”状态,因此,当不再需要它们时,应始终“杀死”它们。来自同一M / S文档:The system copies the bitmaps in the ICONINFO structure before creating the icon or cursor.
...
The application must continue to manage the original bitmaps and delete them when they are no longer necessary.
关于c++ - 将CBitmap转换为HICON并在状态栏上使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61289272/