Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Two toolbars side by side (again!)

Posted on 2004-10-25
Medium Priority
Last Modified: 2013-11-20

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

Question by:fxnut
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 14

Expert Comment

ID: 12405062
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).


Author Comment

ID: 12408936
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.


LVL 14

Expert Comment

ID: 12409711
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.
LVL 14

Accepted Solution

wayside earned 1200 total points
ID: 12423384
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.


Author Comment

ID: 12427870
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.



Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question