Two toolbars side by side (again!)


I know this has been asked many times, but I haven't seen a solution to my particular requirements.

I've got two toolbars and I want them to appear side by side. I know I can do this using "DockControlBar" and the "DockControlBarLeftOf" routine in the MS samples, BUT I **DON'T** want the tool bars to be dockable. As soon as I remove the EnableDocking() calls to the toolbars and main frame window, I get an assert error whenever you make a call to "DockControlBar" (which is necessary to get them side by side).

So either of two solutions will be accepted:

1) Tell me how I can turn off docking AFTER the calls to DockControlBar. (Simply calling EnableDocking(0) doesn't work, since you can still remove the tool bars from the frame - it just doesn't allow you to re-dock them. I want the toolbars to always be static).

or 2) Tell me how to position the toolbars side by side without calling EnableDocking.

Many thanks

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are the toolbars floating or locked in the frame? Floating toolbars are ultimately just windows (they derive from CWnd), and you can use regular CWnd member functions to find out where they are. So try something like this:

1) Find size and location of toolbar1 - GetWindowRect()
2) Use the size and location found it step 1 to compute the coordinates of where toolbar2 has to go in order to be right next to toolbar1
3) Use MoveWindow() or SetWindowPos() to move toolbar2 right next to toolbar1
4) Override OnWindowosChanging() and/or OnWindowPosChanged() for the two toolbars so that if the user moves one, you can move the other as well.

If they are embedded in the frame... IIRC correctly they are placed left to right in one row unless a toolbar would be too long to fit, in which case it would move it down a row. So maybe making the frame big enough to hold them both would fix your problem.

Have you tried calling EnableDocking(0) after the call to DockControlBar()? That is, call EnableDocking(CBRS_ALIGN_ANY), then call DockControlBar(), then call EnableDocking(0).

fxnutAuthor Commented:
Hi Wayside, thanks for your response.

>>Are the toolbars floating or locked in the frame?

I want them to be locked in the frame, located side by side, rather than one above the other. If you turn on docking then this happens. BUT I don't want them to be able to be docked and un-docked.

>>If they are embedded in the frame... IIRC correctly they are placed
>>left to right in one row unless a toolbar would be too long to fit, in
>>which case it would move it down a row.

Unfortunately, no, it doesn't. By default, if you have turned docking off it will place each toolbar one above the other regardless on the parent frame's size. Hence the reason for me asking this question.

>>Have you tried calling EnableDocking(0) after the call to DockControlBar()?

Yes, as I said in my original post, this for some reason doesn't stop the user from floating the windows, it just stops them from docking it again. If you can tell me how to stop them from undocking the toolbars, you've got the points.


I'll take a closer look at the problem.

This is a bit of a hack, but have you considered combining all your toolbars into one large toolbar? If you use separators between them, it looks almost identical to having multiple toolbars.
Well, this has been a tough little nut to crack.

I haven't found a way to line them up in a single row and have them be undockable.

One idea I have which I haven't had a chance to explore yet would be to leave them as dockable, but trap the events that undock them and move them around, and discard or override them. Or similarly, derive my own class from CToolbar and try overriding OnMoving or OnWindowPosChanging or something along those lines.

Seems like the simplest solution is just to combine them into one toolbar. If the toolbar is not dockable, I can't think of any reason why two (or more) toolbars are better than one.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fxnutAuthor Commented:
Okay, thanks Wayside. The main reason I asked this question was that I wanted to know if it was just my lack of knowledge of the Windows API, or if it was really impossible to do. I guess it is, so that answers my question.

I think another alternative is to use a rebar control, which I may well look at.

But for now, thanks for your research.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.