纠结了好一会!汗 void CDResBar::Create(CWnd *pWnd, CRect &rc, UINT ID) { DWORD dwCtrlStyle = TBSTYLE_FLAT; DWORD dwStyle = WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|TBSTYLE_TRANSPARENT|CCS_ADJUSTABLE|CBRS_FLYBY|CBRS_SIZE_FIXED|CBRS_TOOLTIPS|WS_CHILD; CToolBar::CreateEx(pWnd, dwCtrlStyle, dwStyle); this->MoveWindow(rc); _InitToolBarFromXml(); } void CDResBar::_InitToolBarFromXml() { CString path = GetSysfilePath() + _T("Bar.xml"); CXml xml; BOOL b = xml.Open(path); CXmlNodePtr pRoot = xml.GetRoot(); CXmlNodesPtr pNodes = pRoot->GetChildren(); LONG nNum = pNodes->GetCount(); this->SetButtons(NULL, nNum); for(LONG i=0; i<nNum; i++) { CString sName = pNodes->GetItem(i)->GetName(); UINT id = WM_USER+i; this->SetButtonInfo(i, id, TBBS_BUTTON, NULL); this->SetButtonText(i, sName); } }