这个是参考http://www.codeproject.com/KB/toolbars/truecolortoolbar.aspx中显示真彩工具条的方法.
其基本思路是,引入TrueColorToolBar类.其相关代码在上面那个网址有相应的下载方式.
工程中引入类后,如下操作:
#define TOOLBAR_DRAW_BUTTON_WIDTH 24
#include "TrueColorToolBar.h"
class CMainFrame : public CFrameWnd
{
CTrueColorToolBar m_ToolBarDrawLeft;
}
//In Mainframe.cpp
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_ToolBarDrawLeft.SetBorders(1, 1,
1, 1);
if (!m_ToolBarDrawLeft.Create(this, WS_CHILD |
WS_VISIBLE | CBRS_LEFT | CBRS_GRIPPER |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_ToolBarDrawLeft.LoadToolBar(IDR_TOOLBAR_DRAW)) //这块具体的含义可以查MSDN
{
TRACE0("Failed to create toolbar/n");
return -1;
}
m_ToolBarDrawLeft.ModifyStyle(0,
TBSTYLE_FLAT);
m_ToolBarDrawLeft.LoadTrueColorToolBar(
TOOLBAR_DRAW_BUTTON_WIDTH,
IDB_TOOLBAR_DRAW,
IDB_TOOLBAR_DRAW_HOT,
IDB_TOOLBAR_DRAW_DISABLED);
return 0;
}
1.下面解释下,在写以上代码前,需要先准备三张TOOLBAR图象,bitmap格式.IDB_TOOLBAR_DRAW_HOT是按钮能用时的状态. IDB_TOOLBAR_DRAW_DISABLED是按钮禁用时的状态,通常呈灰色.当然,可以根据自己的喜好,设置成不同的颜色.
2.三张图片的尺寸要完全一样,而且,是均分.比如,都是48*48的,若有5个按钮,则总的为48*240.
3.这些做好后可能并不显示,问题是需要在资源视图ToolBar下新建一个ToolBar,如果需要5个按钮,就新建5个按钮,填充上颜色.就可以了.