65.9K
CodeProject 正在变化。 阅读更多。
Home

CTrueColorToolBar

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.79/5 (19投票s)

2002年8月21日

CPOL
viewsIcon

253895

downloadIcon

12044

非常简单的真彩色工具栏(是真的!)。

Sample Image - TrueColorToolBar.jpg

引言

CTrueColorToolBar 是一个真正的真彩色工具栏。该类的实现非常简单。 此工具栏的特点是自动检测位图工具栏第一像素的遮罩颜色。

使用步骤

  1. 在 VC 中创建包含所需按钮数量和最终大小的虚拟 16 色工具栏。
  2. 在您喜欢的绘图工具中,基于第一个工具栏创建 3 个其他真彩色工具栏位图,用于按钮状态(正常、悬停、禁用)。
  3. 将您新的真彩色工具栏导入 VC。
  4. 使用普通工具栏的示例实现创建新的 CTrueColorToolBar 工具栏。
  5. 使用您的 3 个真彩色工具栏位图和按钮的大小调用 LoadTrueColorToolBar 函数。
  6. 就是这样!

示例

//In Mainframe.h
#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); //Fix for WinXP

    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))
    {
        TRACE0("Failed to create toolbar\n");
        return -1; //Failed to create
    }

    m_ToolBarDrawLeft.ModifyStyle(0, 
        TBSTYLE_FLAT);//Fix for WinXP
    m_ToolBarDrawLeft.LoadTrueColorToolBar(
        TOOLBAR_DRAW_BUTTON_WIDTH,
        IDB_TOOLBAR_DRAW,
        IDB_TOOLBAR_DRAW_HOT,
        IDB_TOOLBAR_DRAW_DISABLED);
    return 0;
}

结论

请注意,在 LoadTrueColorToolBar 函数中,如果您省略禁用的工具栏的最后一个参数,您将获得默认的浮雕禁用工具栏。 享受吧!

© . All rights reserved.