使用TBSTYLE_TOOLTIPS 建立toolbar

解决方案 »

  1.   

    在CXDialog的OnCreate函数下:
    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
    }
      

  2.   

    我按kingzai的方法,改成如下,可是还是不行。
    if( !m_wndStatusBar.CreateEx( this,SBT_TOOLTIPS, WS_CHILD|WS_VISIBLE|SBT_TOOLTIPS|CBRS_NOALIGN) ||
    !m_wndStatusBar.SetIndicators( indicators, sizeof( indicators) /sizeof( UINT ) ))
    {   TRACE0( "Failed to create status bar\n" );
    return -1;
    }if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | 
    CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) 
    || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR) )
    {   TRACE0( "Failed to create tool bar\n" );
    return -1;
    }
      

  3.   

    这是因为对话框没有TTN_xxx处理函数,写上邮箱,我发给你一个例子
      

  4.   

    private:
    CToolBarCtrl *m_toolbarCtrl ;
    TBBUTTON btn[5];
    BOOL NotifyFunction( UINT id, NMHDR * pTTTStruct, LRESULT * pResult );
    void SetToolBarPosition(int pos);
    void CDlg_TTBarDlg::SetToolBarPosition(int pos)
    {
    m_toolbarCtrl = NULL ;
    VERIFY(m_toolbarCtrl == NULL );
    m_toolbarCtrl = new CToolBarCtrl() ; CRect wndRect ;
    GetWindowRect(&wndRect);
    CRect rc(0,0,wndRect.right , 50);
    if ( pos == 0 )
    m_toolbarCtrl->Create(TBSTYLE_TOOLTIPS |WS_CHILD | WS_VISIBLE | CCS_TOP | CCS_NODIVIDER, rc ,this , 0 );
    else
    m_toolbarCtrl->Create(TBSTYLE_TOOLTIPS |WS_CHILD | WS_VISIBLE | CCS_BOTTOM  | CCS_NODIVIDER , rc ,this , 0 ); m_toolbarCtrl->AddButtons(5, btn);
    m_toolbarCtrl->AddBitmap(1, IDR_MAINFRAME); CSize sz_btn(30,30);
    m_toolbarCtrl->SetButtonSize(sz_btn);

    CSize sz_img(30,30);
    m_toolbarCtrl->SetBitmapSize(sz_img); m_toolbarCtrl->AutoSize();
    }
    BOOL CDlg_TTBarDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); btn[0].iBitmap = 0 ;
    btn[0].idCommand = ID_NEW ;
    btn[0].fsState = TBSTATE_ENABLED  ;
    btn[0].fsStyle = TBSTYLE_BUTTON  ;
    btn[0].dwData = 0 ;
    btn[0].iString = 0; btn[1].iBitmap = 1 ;
    btn[1].idCommand = ID_LIST ;
    btn[1].fsState = TBSTATE_ENABLED  ;
    btn[1].fsStyle = TBSTYLE_BUTTON ;
    btn[1].dwData = 0 ;
    btn[1].iString = 1; btn[2].iBitmap = 2 ;
    btn[2].idCommand = ID_CUT ;
    btn[2].fsState = TBSTATE_ENABLED  ;
    btn[2].fsStyle = TBSTYLE_BUTTON ;
    btn[2].dwData = 0 ;
    btn[2].iString = 2; btn[3].iBitmap = 3 ;
    btn[3].idCommand = ID_PRINT ;
    btn[3].fsState = TBSTATE_ENABLED  ;
    btn[3].fsStyle = TBSTYLE_BUTTON ;
    btn[3].dwData = 0 ;
    btn[3].iString = 3; btn[4].iBitmap = 4 ;
    btn[4].idCommand = ID_EXIT ;
    btn[4].fsState = TBSTATE_ENABLED  ;
    btn[4].fsStyle = TBSTYLE_BUTTON ;
    btn[4].dwData = 0 ;
    btn[4].iString = 4; EnableToolTips(TRUE); SetToolBarPosition(0); return TRUE;  // return TRUE  unless you set the focus to a control
    }
      

  5.   

    要完全的程序,可给我发邮件:
    [email protected]
      

  6.   

    MSDN中有示例
    CTRLBARS sample (MFC)
      

  7.   

    see DLGCBR32 sample (MFC)in MSDN