一、Create Toolbar on dialog bool CPrjToolBarTestDlg::CreateToolBar() { CString str; CImageList img; //------------------------------------------------------------------------------------ //if(!m_tb.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC)) if(!m_tb.CreateEx(this)) { TRACE0("Failed to create toolbar/n"); return false; // fail to create; } m_tb.GetToolBarCtrl().SetButtonWidth(50, 50); m_tb.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS); m_tb.ModifyStyle(0, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT); //-------------------------------------------------------------- //Set Buttons Count m_tb.SetButtons(NULL, 2); // set up toolbar button sizes m_tb.SetSizes(CSize(50,50), CSize(40,40)); //Set Button's Icon img.Create(IDB_bmpCOLDTOOLBAR, 22, 0, RGB(255, 0, 255)); m_tb.GetToolBarCtrl().SetImageList(&img); img.Detach(); img.Create(IDB_bmpHOTTOOLBAR, 22, 0, RGB(255, 0, 255)); m_tb.GetToolBarCtrl().SetHotImageList(&img); img.Detach(); //-------------------------------------------------------------- //Set each Button m_tb.SetButtonInfo(0, ID_Back, TBSTYLE_BUTTON, 0); //CString str("Back"); //m_tb.SetButtonText(0, str); m_tb.SetButtonText(0, "Back"); m_tb.SetButtonInfo(1, ID_Refresh, TBSTYLE_BUTTON, 3); str = "Refresh"; m_tb.SetButtonText(1, str); m_tb.SetBarStyle(m_tb.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED); RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); //------------------------------------------------------------------------------------ return true; } 二、Response the message 1、Add the message map BEGIN_MESSAGE_MAP(CPrjToolBarTestDlg, CDialog) //{{AFX_MSG_MAP(CPrjToolBarTestDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_COMMAND(ID_Back,OnBack) ON_COMMAND(ID_Refresh,OnRefresh) //}}AFX_MSG_MAP END_MESSAGE_MAP() 2、Reponse the message void CPrjToolBarTestDlg::OnBack() { MessageBox("CPrjToolBarTestDlg::OnBack: Back"); } void CPrjToolBarTestDlg::OnRefresh() { MessageBox("CPrjToolBarTestDlg::OnRefresh: Refresh"); }