不是把所有按钮做成一个长条形的bmp位图,这个我知道。我的意思是:
我想对应每一个工具栏按钮,自己设置按钮的图片,图片是从网上一个一个的下载的。
就是分别设置每个工具栏按钮的图片,图片可以是真彩色的。
还要可以同时显示图片和文字,比如图片在上,文字在下。CMFCToolBar怎么实现这个功能?VS2005的CToolBar我知道可以用CImageList来实现,
但是不会用VS2010的CMFCToolBar。

解决方案 »

  1.   


    CSize btnSize=CMFCToolBar::GetMenuButtonSize();
    CSize imgSize=CMFCToolBar::GetMenuImageSize();
    imgSize.cx=16;//这里的宽,高要和工具栏图标统一.默认的是 16x15
    imgSize.cy=16;
    CMFCToolBar::SetMenuSizes(btnSize,imgSize);//注意,以前几句, 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_256,IDB_BITMAP4,IDB_BITMAP4,FALSE,0,0,IDB_BITMAP4))//这里IDR_MAINFRAME_256是你的工具栏ID, 后面IDB_BITMAP4是工具栏真彩位图资源ID.注意宽高要和工具栏相同,否则会出现断言失败.
    {
    TRACE0("未能创建工具栏\n");
    return -1;      // 未能创建
    }
      

  2.   

    你可以在在线MSDN中去下载一个IEDemo看看.
    http://archive.msdn.microsoft.com/vcsamplesmfc
      

  3.   

    CMFCToolbar也就是BCG中的CBCGPToolbar
      

  4.   


    那我这个问题怎么解决呢?就像C#的striptoolbar工具条一样,可以分别设置每个按钮的图片。这些图片可以是从网上下载的
    png,icon等格式的。
      

  5.   

    CBCGPToolBar
    The CBCGToolBar class extends the MFC toolbar control by providing support for a number of features:Full customization 
    Drag and drop buttons between toolbars and menus 
    Flat toolbars 
    Toolbars with the "hot" images (Microsoft� Internet Explorer�-style) 
    Large icons support 
    "Pager" button (allows to see out of screen commands) 
    "Locked" toolbars 
    Auto-build keyboard shortcuts names in menus and ToolTips 
    Rebar support 
    Text below images 
    Built-in combo box buttons 
    Built-in edit box buttons 
    Built-in color picker 
    Built-in roll-up buttons (similar to CorelDraw�) 
    Microsoft� Office 2000 look 
    Transparent toolbars with background image 
    CBCGPToolBar is the base class for several important BCGPro ControlBar Library classes CBCGPMenuBar, CBCGPPopupMenuBar, CBCGDropDownToolBar.To incorporate CBCGPToolBar into your application, you need to perform the following steps:Embed a CBCGPToolBar object into the main frame window. 
    When processing WM_CREATE message for the main frame window call either Create or CreateEx and specify the desired toolbar styles. 
    Call EnableDocking and specify the desired docking style. 
    If you need to insert into the toolbar some "non-standard" button (meaning, a CBCGToolBarButton-derived object, like combo box button), you need to reserve some dummy button at the design time and then replace the dummy button at runtime by the ReplaceButton function.
    See Also   CBCGPMenuBarClass Members | Hierarchy Chart