Trouble docking a second toolbar 
Author Message
 Trouble docking a second toolbar

Hello. I'm getting an assert error when I attempt to dock a second
toolbar. If I comment out the code to dock the second toolbar, then it
shows up as the top most toolbar, so I'm assuming it's getting created
properly. Each of my toolbars are CToolBar derived classes (CTextToolBar
: CToolBar) && (CSecondToolBar : CToolBar). The only code in the second
toolbar is in OnCreate, where I load the toolbar with the resource ID
(IDR_MAINFRMTWO). Here is my CMainFrame's OnCreate function where the
toolbars are created. I've bolded out the point in the code where I get
an assert failure. The failure is in
CDockContext::CDockContext(CControlBar* pBar), the specific failure
being ASSERT(pBar->m_pDockSite != NULL);

The first toolbar that's created here and docked works fine.  Any help
in figurring out what's wrong will be greatly appreciated. Ed :)

Here's the code creating the toolbars:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{

      if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

      if (!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
          | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY |
CBRS_SIZE_DYNAMIC) )
      {
            TRACE0("Failed to create toolbar\n");
             return -1;      // fail to create
       }

       // create the second toolbar
       if(!m_wndToolBar1.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP |

          CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
IDR_MAINFRMTWO ) )
       {
            TRACE0("Failed to create the second toolbar\n");
            return -1;
        }
        // enable docking
        EnableDocking(CBRS_ALIGN_ANY);

        // dock the toolbar
       m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
       DockControlBar(&m_wndToolBar);

        // dock the second toolbar
        TRACE0("before second toolbar enable docking\n");
        m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY); // assert failure
here
        TRACE0("after second toolbar enable docking\n");
        DockControlBar(&m_wndToolBar1);

        return 0;

Quote:
}



Fri, 24 Oct 2003 08:41:08 GMT  
 Trouble docking a second toolbar
You have not yet loaded the toolbars using LoadToolBar, identical to the
code generated by the wizard. I dont know if thats the only problem. Each
toolbar should  have a distinct ID(last parameter in CToolBar::Create()).

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.



Hello. I'm getting an assert error when I attempt to dock a second toolbar.
If I comment out the code to dock the second toolbar, then it shows up as
the top most toolbar, so I'm assuming it's getting created properly. Each of
my toolbars are CToolBar derived classes (CTextToolBar : CToolBar) &&
(CSecondToolBar : CToolBar). The only code in the second toolbar is in
OnCreate, where I load the toolbar with the resource ID (IDR_MAINFRMTWO).
Here is my CMainFrame's OnCreate function where the toolbars are created.
I've bolded out the point in the code where I get an assert failure. The
failure is in CDockContext::CDockContext(CControlBar* pBar), the specific
failure being ASSERT(pBar->m_pDockSite != NULL);
The first toolbar that's created here and docked works fine.  Any help in
figurring out what's wrong will be greatly appreciated. Ed :)
Here's the code creating the toolbars:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

      if (!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
          | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) )
      {
            TRACE0("Failed to create toolbar\n");
             return -1;      // fail to create
       }
       // create the second toolbar
       if(!m_wndToolBar1.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP |
          CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
IDR_MAINFRMTWO ) )
       {
            TRACE0("Failed to create the second toolbar\n");
            return -1;
        }
        // enable docking
        EnableDocking(CBRS_ALIGN_ANY);
        // dock the toolbar
       m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
       DockControlBar(&m_wndToolBar);
        // dock the second toolbar
        TRACE0("before second toolbar enable docking\n");
        m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY); // assert failure here
        TRACE0("after second toolbar enable docking\n");
        DockControlBar(&m_wndToolBar1);

        return 0;

Quote:
}



Fri, 24 Oct 2003 09:11:28 GMT  
 Trouble docking a second toolbar
This only strengthens my view for not using the wizard for simple things.
(It will be brain dead to not use it in ATL and ActiveX control
developments)

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.



Quote:
> Hi, Ajay. I'm loading the toolbars in each of the derived OnCreate
functions of
> the CToolBar derived classes. The problem turned out to be with the
toolbar's
> OnCreate function. Appwizzard doesn't give you the option of deriving from
> CToolBar. So I derived from a generic CWnd. Prior to changing the
derivation to
> CToolBar, I had handled the WM_CREATE message. That made the base class
call in
> OnCreate call CWnd::OnCreate...which was the problem. I missed this. The
fix was
> to call CToolBar::OnCreate when calling the derived toolbar's base class.

> Ed :)


> > You have not yet loaded the toolbars using LoadToolBar, identical to the
> > code generated by the wizard. I dont know if thats the only problem.
Each
> > toolbar should  have a distinct ID(last parameter in

CToolBar::Create()).

- Show quoted text -

Quote:

> > --
> > Ajay Kalra [MVP - VC++]

> > Note: Please post all replies to newsgroup only.



> > Hello. I'm getting an assert error when I attempt to dock a second
toolbar.
> > If I comment out the code to dock the second toolbar, then it shows up
as
> > the top most toolbar, so I'm assuming it's getting created properly.
Each of
> > my toolbars are CToolBar derived classes (CTextToolBar : CToolBar) &&
> > (CSecondToolBar : CToolBar). The only code in the second toolbar is in
> > OnCreate, where I load the toolbar with the resource ID
(IDR_MAINFRMTWO).
> > Here is my CMainFrame's OnCreate function where the toolbars are
created.
> > I've bolded out the point in the code where I get an assert failure. The
> > failure is in CDockContext::CDockContext(CControlBar* pBar), the
specific
> > failure being ASSERT(pBar->m_pDockSite != NULL);
> > The first toolbar that's created here and docked works fine.  Any help
in
> > figurring out what's wrong will be greatly appreciated. Ed :)
> > Here's the code creating the toolbars:
> > int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
> > {
> >       if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
> >         return -1;

> >       if (!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
> >           | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY |

CBRS_SIZE_DYNAMIC) )

- Show quoted text -

Quote:
> >       {
> >             TRACE0("Failed to create toolbar\n");
> >              return -1;      // fail to create
> >        }
> >        // create the second toolbar
> >        if(!m_wndToolBar1.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP |
> >           CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
> > IDR_MAINFRMTWO ) )
> >        {
> >             TRACE0("Failed to create the second toolbar\n");
> >             return -1;
> >         }
> >         // enable docking
> >         EnableDocking(CBRS_ALIGN_ANY);
> >         // dock the toolbar
> >        m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
> >        DockControlBar(&m_wndToolBar);
> >         // dock the second toolbar
> >         TRACE0("before second toolbar enable docking\n");
> >         m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY); // assert failure
here
> >         TRACE0("after second toolbar enable docking\n");
> >         DockControlBar(&m_wndToolBar1);

> >         return 0;
> > }



Fri, 24 Oct 2003 17:18:06 GMT  
 Trouble docking a second toolbar
Hi, Ajay. I'm loading the toolbars in each of the derived OnCreate functions of
the CToolBar derived classes. The problem turned out to be with the toolbar's
OnCreate function. Appwizzard doesn't give you the option of deriving from
CToolBar. So I derived from a generic CWnd. Prior to changing the derivation to
CToolBar, I had handled the WM_CREATE message. That made the base class call in
OnCreate call CWnd::OnCreate...which was the problem. I missed this. The fix was
to call CToolBar::OnCreate when calling the derived toolbar's base class.

Ed :)

Quote:

> You have not yet loaded the toolbars using LoadToolBar, identical to the
> code generated by the wizard. I dont know if thats the only problem. Each
> toolbar should  have a distinct ID(last parameter in CToolBar::Create()).

> --
> Ajay Kalra [MVP - VC++]

> Note: Please post all replies to newsgroup only.



> Hello. I'm getting an assert error when I attempt to dock a second toolbar.
> If I comment out the code to dock the second toolbar, then it shows up as
> the top most toolbar, so I'm assuming it's getting created properly. Each of
> my toolbars are CToolBar derived classes (CTextToolBar : CToolBar) &&
> (CSecondToolBar : CToolBar). The only code in the second toolbar is in
> OnCreate, where I load the toolbar with the resource ID (IDR_MAINFRMTWO).
> Here is my CMainFrame's OnCreate function where the toolbars are created.
> I've bolded out the point in the code where I get an assert failure. The
> failure is in CDockContext::CDockContext(CControlBar* pBar), the specific
> failure being ASSERT(pBar->m_pDockSite != NULL);
> The first toolbar that's created here and docked works fine.  Any help in
> figurring out what's wrong will be greatly appreciated. Ed :)
> Here's the code creating the toolbars:
> int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
> {
>       if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
>         return -1;

>       if (!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
>           | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) )
>       {
>             TRACE0("Failed to create toolbar\n");
>              return -1;      // fail to create
>        }
>        // create the second toolbar
>        if(!m_wndToolBar1.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP |
>           CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
> IDR_MAINFRMTWO ) )
>        {
>             TRACE0("Failed to create the second toolbar\n");
>             return -1;
>         }
>         // enable docking
>         EnableDocking(CBRS_ALIGN_ANY);
>         // dock the toolbar
>        m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
>        DockControlBar(&m_wndToolBar);
>         // dock the second toolbar
>         TRACE0("before second toolbar enable docking\n");
>         m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY); // assert failure here
>         TRACE0("after second toolbar enable docking\n");
>         DockControlBar(&m_wndToolBar1);

>         return 0;
> }



Fri, 24 Oct 2003 16:49:53 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Q: How to dock a Toolbar next to the First Toolbar

2. How to dock a toolbar beside the main toolbar

3. WTL docking toolbars

4. toolbar docking problem

5. flat menus and docking toolbars

6. S.O.S.!!! - Need help for resizable-docked toolbars

7. toolbar: which side its docked to?

8. Expert required: Solution to setting a docked toolbars width (or number of columns)

9. toolbar 's docking problem

10. Wrapping with a docked toolbar

11. which side is the toolbar docked

12. Docking toolbars side-by-side

 

 
Powered by phpBB® Forum Software