MFC.怎么释放m_wndtoolbar.LoadToolBar()已加载的IDR_TOOLBAR1

MFC.如何释放m_wndtoolbar.LoadToolBar()已加载的IDR_TOOLBAR1
BOOL CCutLineAIDC::OnInitDialog() 
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here

CRect rect;
GetClientRect(rect);

if (!m_hpglView.Create(rect, this))
return -1;

//CToolBar p_wndtoolbar = new CToolBar; //20150415
//*m_wndtoolbar = p_wndtoolbar; //20150415
//20150323rwt toolbar
if ((!m_wndtoolbar.CreateEx( this,TBSTYLE_FLAT ,  WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS,
CRect(4,4,0,0))) || (!m_wndtoolbar.LoadToolBar(IDR_TOOLBAR1)))
{
TRACE0("failed to create toolbar\n");
return false;
}

//* 20150415-rwt
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CRect rcClientOld; // Old Client Rect
CRect rcClientNew; // New Client Rect with Tollbar Added
GetClientRect(rcClientOld); // Retrive the Old Client WindowSize
// Called to reposition and resize control bars in the client area of a window
// The reposQuery FLAG does not really traw the Toolbar. It only does the calculations.
// And puts the new ClientRect values in rcClientNew so we can do the rest of the Math.
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);
// All of the Child Windows (Controls) now need to be moved so the Tollbar does not cover them up.
// Offest to move all child controls after adding Tollbar
CPoint ptOffset(rcClientNew.left-rcClientOld.left,rcClientNew.top-rcClientOld.top);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD); //Handle to the Dialog Controls
while(pwndChild) // Cycle through all child controls
{
pwndChild->GetWindowRect(rcChild); // Get the child control RECT
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset); // Changes the Child Rect by the values of the claculated offset
pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
pwndChild = pwndChild->GetNextWindow();
}
CRect rcWindow;
GetWindowRect(rcWindow); // Get the RECT of the Dialog
rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // Increase width to new Client Width
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); // Increase height to new Client Height
MoveWindow(rcWindow,FALSE); // Redraw Window
// Now we REALLY Redraw the Toolbar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); 
//*/


//m_wndtoolbar.MoveWindow(0,0, 100, 40,TRUE);//20150415-rwt
return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}

m_wndtoolbar.LoadToolBar(IDR_TOOLBAR1) 第一次执行返回值是对的,第二次在执行的时候 返回值就为0了,工具条在打开的窗口中就显示不出来了,如果屏蔽到if()里的return,工具条 框架能显示出来,但是图标都没有了,求大神帮忙,不知道是不是没有释放掉加载的toolbar,如何释放,
------解决思路----------------------
m_wndtoolbar.CreateEx 之前调用一次 m_wndtoolbar.DestroyWindow( ); 试试看

------解决思路----------------------
你可以使用CToolBar::GetToolBarCtrl()得到CToolBarCtrl对象,然后利用CToolBarCtrl::AddButtons()/DeleteButton/HideButton()等来实现你的功能,没有必要重新Load.