Solved

How to set location of MFC application toolbars under VC++5.0

Posted on 1997-11-18
15
698 Views
Last Modified: 2013-12-03
I want to set the location of several toobars ie

TB1............
_______________T
Document View__B
_______________2

_______________T
_______________B
_______________3

I am able to manually place (dock) the tool bars where I want them, but how do I make these positions the default?

The come up like this instead

TB1
TB2
TB3
Document View
0
Comment
Question by:sherwingw
  • 11
  • 3
15 Comments
 

Author Comment

by:sherwingw
ID: 1408513
Edited text of question
0
 

Author Comment

by:sherwingw
ID: 1408514
Edited text of question
0
 

Author Comment

by:sherwingw
ID: 1408515
Edited text of question
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1408516
If you look at the generated code for the toolbars. In that section, you'll see SetBarStyle(...., CBRS_SIZE_DYNAMIC);
Add either  
  | CBRS_TOP  or
  | CBRS_RIGHT to the style of the toolbar you want to position.

For example,

  .SetBarStyle(...., CBRS_SIZE_DYNAMIC | CBRS_RIGHT) to position it to the right of the view.
0
 

Author Comment

by:sherwingw
ID: 1408517
Causes an assertion failure:
m_wndTestToolBar.SetBarStyle(m_wndTestToolBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC |             CBRS_RIGHT);

Does Not cause failure but requires manual position:
m_wndTestToolBar.SetBarStyle(m_wndTestToolBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

0
 

Author Comment

by:sherwingw
ID: 1408518
Well, I'm part way there,  I can now get one toolbar at the top-left and one along the right by using:

m_wndTestToolBar1.SetBarStyle(0);
 m_wndTestToolBar1.SetBarStyle(CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_TOP);

m_wndTestToolBar2.SetBarStyle(0);
 m_wndTestToolBar2.SetBarStyle(CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_RIGHT);

But If I try to add additional toolbars along the right side, they stack beside each other instead of below the preceeding one.

I know that if I can manually dock them to the correct position, there has to be a way.

INCIDENTLY:  The GetaBarStyle() call causes CBRS_RIGHT to clash with CBRS_TOP, They are mutually exclusive acording to the .h file
0
 

Author Comment

by:sherwingw
ID: 1408519
Adjusted points to 250
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:sherwingw
ID: 1408520
Adjusted points to 300
0
 
LVL 1

Accepted Solution

by:
Tiutin earned 400 total points
ID: 1408521
The MFC Documentation contains ToolBar Samples, one of them being DOCKTOOL. It demonstrates dockable toolbar support.
As the documentation says:
"...A dockable toolbar can be attached, or docked, to any side of its parent window, or it can be detached, or floated, in its own mini-frame window using CMiniFrameWnd. The following three steps are necessary to place a dockable toolbar in your application:

Enable docking for the frame window or destination using the CFrameWnd::EnableDocking function. One DWORD parameter indicates which side of the frame window accepts docking. To dock control bars anywhere, pass CBRS_ALIGN_ANY to EnableDocking.
Enable docking for the toolbar or source by calling CControlBar::EnableDocking for each toolbar.
Specify the destination sides to which the toolbar should dock. If none of the sides specified match the sides enabled for docking in the frame window, the toolbar cannot dock — it will float. Once it has been floated, it remains a floating toolbar, unable to dock to the frame window.
Dock the toolbar to the frame window by calling CFrameWnd::DockControlBar. Conversely, call CFrameWnd::FloatControlBar to detach a dockable toolbar from the frame window.
If you do not complete all three steps, your application will display a standard toolbar. The last two steps must be performed for each dockable toolbar in your application.

To retain the state of dockable toolbars (whether docked or floating) between invocations of your application, use the CControlBar::SetBarStyle and CControlBar::GetBarStyle functions to retrieve and restore the settings of any particular control bar.
Normally, this information is stored in the application's .ini file using CFrameWnd::SaveBarState and retrieved using CFrameWnd::LoadBarState...".

Below is description of CFrameWnd::DockControlBar fuction (just for notice).

void DockControlBar( CControlBar * pBar, UINT nDockBarID = 0, LPCRECT lpRect = NULL );
Parameters
pBar   Points to the control bar to be docked.
nDockBarID   Determines which sides of the frame window to consider for docking.
It can be 0, or one or more of the following:

AFX_IDW_DOCKBAR_TOP   Dock to the top side of the frame window.
AFX_IDW_DOCKBAR_BOTTOM   Dock to the bottom side of the frame window.
AFX_IDW_DOCKBAR_LEFT   Dock to the left side of the frame window.
AFX_IDW_DOCKBAR_RIGHT   Dock to the right side of the frame window.

If 0, the control bar can be docked to any side enabled for docking in the destination frame window.

lpRect   Determines, in screen coordinates, where the control bar will be docked in the nonclient area of the destination frame window.

Remarks

Causes a control bar to be docked to the frame window. The control bar will be docked to one of the sides of the frame window specified in the calls to both CControlBar::EnableDocking and CFrameWnd::EnableDocking. The side chosen is determined by nDockBarID.

See Also   CFrameWnd::FloatControlBar

May be this is an answer?
Regards.

0
 

Author Comment

by:sherwingw
ID: 1408522
I want to fix the location of the toolbars.
I do not want to have the user dock them I do not want to dock
them.  I do not want the user to be able to change them.  I want
them to go where I want them to go.  Can I dock them using:

void DockControlBar( CControlBar * pBar, UINT nDockBarID = 0, LPCRECT lpRect = NULL );

and then disable docking somehow?  How do I determine the correct
value for lpRect?

I want the toolbars arranged as follows.

              ToolBar1 Along the top edge, starting in the
              left corner (THIS IS EASY,Its the default Top
              position as shown in the code fragrement above)

              ToolBar2 Along the Right edge, starting at the
              top corner.  (This also easy as shown in the
              code fragment above)

NOW COMES THE TROUBLE

              ToolBar3 Butted against the lower edge of ToolBar2

AND MORE TROUBLE

              ToolBar4 Below Toolbar3 with space between them

AND FINALY    ToolBar5 Butted against the lower edge of toolBar4
              ( If we solve ToolBar3 then this will be the same)

ADDITIONAL INFO:

              ToolBar2 and Toolbar4 have a different aspect ratio
              than ToolBars 3 and 5 so they can't be made as one
              long tool bar
0
 

Author Comment

by:sherwingw
ID: 1408523
void DockControlBar( CControlBar * pBar,
                     UINT nDockBarID = 0,
                     LPCRECT lpRect = NULL );
works SORT OF:

The bars do not position where you would expect them to.
However, by properly ordering the dock calls for each ToolBar(bottom to top) and using 0,0 for the upper left corner of each bar, and width,height for the lower right corner of each bar I can get the bars to stack in the proper order.  I can not get them to leave space between bars.  I got around this by using yet another ToolBar as a spacer.

This is a GIGANTIC CLUDGE. and what is more, it does not provide a stable position for the ToolBars.  If the user resizes the window, too small, the ToolBars again do their own thing.

Reminder:  I realy do not want dockable bars.  I want them in a fixed position. I do not want the user to have the option of moving them.  I do not want Windows to rearage them.
0
 
LVL 1

Expert Comment

by:Tiutin
ID: 1408524
General MFC Samples include DOCKTOOL that demonstrates dockable toolbar support. A dockable toolbar can be attached, or docked, to any side of its parent window, or it can be detached, or floated, in its own mini-frame window using CMiniFrameWnd. The following three steps are necessary to place a dockable toolbar in your application:

(1) Enable docking for the frame window or destination using the CFrameWnd::EnableDocking function. One DWORD parameter indicates which side of the frame window accepts docking. To dock control bars anywhere, pass CBRS_ALIGN_ANY to EnableDocking.

(2) Enable docking for the toolbar or source by calling CControlBar::EnableDocking for each toolbar. Specify the destination sides to which the toolbar should dock. If none of the sides specified match the sides enabled for docking in the frame window, the toolbar cannot dock — it will float. Once it has been floated, it remains a floating toolbar, unable to dock to the frame window.

(3) Dock the toolbar to the frame window by calling CFrameWnd::DockControlBar. Conversely, call CFrameWnd::FloatControlBar to detach a dockable toolbar from the frame window.

If you do not complete all three steps, your application will display a standard toolbar. The last two steps must be performed for each dockable toolbar in your application.

To retain the state of dockable toolbars (whether docked or floating) between invocations of your application, use the CControlBar::SetBarStyle and CControlBar::GetBarStyle functions to retrieve and restore the settings of any particular control bar. Normally, this information is stored in the application's .ini file using CFrameWnd::SaveBarState and retrieved using CFrameWnd::LoadBarState.

The docking, floating, and tool tips calls are optional. You can remove those lines from OnCreate if you prefer. The result is a toolbar that remains fixed, unable to float or redock and unable to display tool tips.

If you wish I may send you the whole bunch.
Regards.
0
 

Author Comment

by:sherwingw
ID: 1408525
I know how to produce dockable ToolBars!  What I can not figure out is how to position FIXED ToolBars. or for that matter how to predictably position multiple Dockable ToolBars.  If you read the history of this question, you will see that I already have been using dockable bars.  The problem is I DON"T WANT DOCKABLE
BARS! I WANT FIXED BARS!  in the position I have designed.
0
 

Author Comment

by:sherwingw
ID: 1408526
Adjusted points to 400
0
 
LVL 1

Expert Comment

by:Tiutin
ID: 1408527
400 points won't go. Now it is your problem to look at DOCKTOOL example while taking into consideration the following comment:
"...  The docking, floating, and tool tips calls are optional. You can remove those lines from OnCreate if you prefer. The result is a toolbar that remains fixed, unable to float or redock and unable to display tool tips...".
I am finished.
Good luck.
0

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

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual Studio Exe Issue, 12 25
Insert filename column as column a 18 71
Using MS Code on my Mac 6 47
Trouble with References... 5 26
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 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

12 Experts available now in Live!

Get 1:1 Help Now