MFC 工具栏图标的颜色深度更高? [英] Higher color depth for MFC toolbar icons?

查看:14
本文介绍了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 工具栏图标的颜色深度更高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆