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 工具栏图标的颜色深度更高?


基础教程推荐
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01