1
votes

This question is a follow up of my previous question. First thanks for the links and examples, they do work voor a CMDIChildWnd derived CChildFrame class, but not for a CMDIChildWndEx derived one.

What i want to do:

I want to create a toolbar in the CChildFrame window (derived from CMDIChildWndEx !!)

What i have done so far: 1) Created a MDI Tabbed documents CView project using VS2008Pro App-wizard. 2) In CChildFrame i added OnCreate()

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1) return -1;

    // TODO:  Add your specialized creation code here 
    if (!m_wndToolBar.Create(this) || 
       !m_wndToolBar.LoadToolBar(IDR_CHILDFRAME)) 
   { 
       TRACE0("Failed to create toolbar\n"); 
       return -1;      // fail to create 
   } 


   // TODO: Remove this if you don't want tool tips or a 
   // resizeable toolbar 
   m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | 
       CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); 


   // TODO: Delete these three lines if you don't want the toolbar 
   // to be dockable 
   m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 
   EnableDocking(CBRS_ALIGN_ANY); 
   DockControlBar(&m_wndToolBar);    // Goes wrong here !!


    return 0; 

}

it compiles and runs and halts into an ASSERT in winfrm2.cpp (line 92) :

void CFrameWnd::DockControlBar(CControlBar* pBar, CDockBar* pDockBar, LPCRECT lpRect) { ENSURE_ARG(pBar != NULL); // make sure CControlBar::EnableDocking has been called ASSERT(pBar->m_pDockContext != NULL);

    if (pDockBar == NULL) 
    { 
            for (int i = 0; i < 4; i++) 
            { 
                    if ((dwDockBarMap[i][1] & CBRS_ALIGN_ANY) == 
                            (pBar->m_dwStyle & CBRS_ALIGN_ANY)) 
                    { 
                            pDockBar = (CDockBar*)GetControlBar(dwDockBarMap[i][0]); 

/* --------> goes wrong here ------> */ ASSERT(pDockBar != NULL); // assert fails when initial CBRS_ of bar does not // match available docking sites, as set by EnableDocking() break; } } } ENSURE_ARG(pDockBar != NULL); ASSERT(m_listControlBars.Find(pBar) != NULL); ASSERT(pBar->m_pDockSite == this); // if this assertion occurred it is because the parent of pBar was not initially // this CFrameWnd when pBar's OnCreate was called // i.e. this control bar should have been created with a different parent initially

    pDockBar->DockControlBar(pBar, lpRect); 

}

in line 92 :

ASSERT(pDockBar != NULL); // assert fails when initial CBRS_ of bar does not // match available docking sites, as set by EnableDocking()

the source here even gives some explanation of what goes wrong here but i dont know how to match 'initial CBRS_ of bar with those set by EnableDocking()''

Does this even work for a CMDIChildWndEx derived CChildFrame class ?

Well so my question is does any one know how to add a toolbar to a CMDIChildWndEx derived CChildFrame class ? Any suggestions on how to get this working ?

My project is here : http://www.4shared.com/file/235762968/49b8b97a/GUI50.html

Any help would be greatly appreciated !

2

2 Answers

3
votes

This seems to work for a CMFCToolBar

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1)
    return -1;

   m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_CHILDFRAME);
   m_wndToolBar.LoadToolBar(IDR_CHILDFRAME, 0, 0, TRUE );
   m_wndToolBar.SetPaneStyle( CBRS_TOOLTIPS | CBRS_FLYBY| CBRS_BOTTOM); 
   m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
   EnableDocking(CBRS_ALIGN_ANY);
   DockPane(&m_wndToolBar);

   return 0;
 }
1
votes

You should set m_bEnableFloatingBars = TRUE in MDIChild constructor. Without this your toolbar will no be docked by mouse, only static docking.