Two toolbars side by side (again!)

Posted on 2004-10-25
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
    LVL 14

    Expert Comment

    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).

    LVL 1

    Author Comment

    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

    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

    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.

    LVL 1

    Author Comment

    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.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    if loop error 4 63
    Expand to include initial dialog with two choices. 9 48
    Hibernate methods 2 33
    bigDiff challenge 17 47
    Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    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.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    857 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now