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

查看:334
本文介绍了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天全站免登陆