if (!m_ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_ToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1;      // fail to create
}
我做的是一个基于对话框的程序。为动态创建的工具栏添加了消息映射,运行后 工具栏上的图标都是灰的 不知道怎么解决了
BEGIN_MESSAGE_MAP(CTChartDlg, CDialog)
//{{AFX_MSG_MAP(CTChartDlg)
ON_COMMAND(ID_TEMP_RANGE, OnTempRange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
ID_TEMP_RANGE为工具栏上的图标ID

解决方案 »

  1.   

    你怎么把工具栏加载到dialog的?这一部分代码也贴出来。
      

  2.   

    哦 我是在对话框程序动态添加工具栏的 在OnCreate里面
    if (!m_ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_ToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
    TRACE0("Failed to create toolbar\n");
    return -1; // fail to create
    }
    问题就是 运行的时候 这些图标都是灰的 已经添加了消息映射了 还是灰的 不知道怎么弄了 
      

  3.   

    h头文件中CToolBar m_ToolBar;//工具栏上的按钮的ID是连续的,如果不连续,一个按钮一个响应,或者修改为连续的,视情况而定
    afx_msg void OnBnClickedToolBar(UINT nID);cpp文件中//消息映射部分
    ON_COMMAND_RANGE(ID_BUTTON_1, ID_BUTTON_N, OnBnClickedToolBar)// OnInitDialog函数中
    if(!m_ToolBar.CreateEx(this, TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC) || !m_ToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
    AfxMessageBox(_T("Create ToolBar failed."));
    return FALSE;
    }
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);//工具栏上按钮的消息响应
    void CXXXDlg::OnBnClickedToolBar(UINT nID)
    {
    int nIndex = nID - ID_BUTTON_1;
    CString strText(_T(""));
    strText.Format(_T("You select index: %d"), nIndex + 1);
    AfxMessageBox(strText);
    }