Higher color depth for MFC toolbar icons?(MFC 工具栏图标的颜色深度更高?)
问题描述
我想知道如何在 MFC 中制作一个使用 24 位或 256 色位图而不是可怕的 16 色位图的工具栏.
I was wondering how to make a toolbar in MFC that used 24bit or 256 colour bitmaps rather than the horrible 16 colour ones.
谁能指出一些简单代码的方向?
Can anyone point me in the direction of some simple code?
谢谢
推荐答案
发生这种情况的原因是 MFC CToolbar 类在内部使用了一个图像列表,该列表被初始化为仅使用 16 种颜色.解决方案是创建我们自己的图像列表并告诉工具栏使用它.我知道这适用于 256 色,但我还没有用更高的位深度测试它:
The reason this happens is that the MFC CToolbar class uses an image list internally that is initialised to use 16 colours only. The solution is to create our own image list and tell the toolbar to use that instead. I know this will work for 256-colours, but I haven't tested it with higher bit-depths:
首先,从资源中加载 256 色位图:
First, load a 256-colour bitmap from a resource:
HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_BITMAP,
0,0, LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS);
CBitmap bm;
bm.Attach(hBitmap);
接下来,创建一个 256 色图像列表并将我们的位图添加到其中:
Next, create a 256-colour image list and add our bitmap to it:
CImageList m_imagelist.Create(20, 20, ILC_COLOR8, 4, 4);
m_imagelist.Add(&bm, (CBitmap*) NULL);
最后,我们需要告诉工具栏使用新的图片列表:
Finally, we need to tell the toolbar to use the new image list:
m_toolbar.GetToolBarCtrl().SetImageList(&m_imagelist);
VS2008 中的新 MFC 版本也可能解决了这个问题,因为我知道许多 UI 元素已经更新.我还没有真正尝试过使用它,所以我不能确定.
It's also possible that the new MFC version in VS2008 may have solved this problem as I know that many of the UI elements have been updated. I haven't actually tried using it yet so I can't be certain.
这篇关于MFC 工具栏图标的颜色深度更高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MFC 工具栏图标的颜色深度更高?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
