在头文件中定义:
private:
CImageList image;
CToolBar toolbar;
CBitmap bmp;在dlg.cpp中代码如下:写在OnInitDialog函数中image.Create(48,48,ILC_COLOR32|ILC_MASK,2,2);
bmp.LoadBitmap(IDB_BITMAP1);
bmp.DeleteObject();
bmp.LoadBitmap(IDB_BITMAP2);
bmp.DeleteObject();
toolbar.CreateEx(this);
toolbar.GetToolBarCtrl().SetImageList(&image);toolbarMFCBitmaptoolbarctrl
private:
CImageList image;
CToolBar toolbar;
CBitmap bmp;在dlg.cpp中代码如下:写在OnInitDialog函数中image.Create(48,48,ILC_COLOR32|ILC_MASK,2,2);
bmp.LoadBitmap(IDB_BITMAP1);
bmp.DeleteObject();
bmp.LoadBitmap(IDB_BITMAP2);
bmp.DeleteObject();
toolbar.CreateEx(this);
toolbar.GetToolBarCtrl().SetImageList(&image);toolbarMFCBitmaptoolbarctrl
if (!m_wndToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_TOOLTIPS) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
AfxMessageBox("Failed to create toolbar\n");
return -1; // fail to create
} RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
问题解决,多谢。