Solved

Deriving from CToolBar

Posted on 1997-04-05
5
451 Views
Last Modified: 2013-11-20


I have the need for a CToolBar derived toolbar that contains no bitmapped buttons. I want it to contain only Combo boxes (5 in total). There is a sample called DOCTOOL (from VC 4.2) that comes close to what I want. It derives from CToolBar then uses the ability to resize the ID_SEPARATOR sections of the toolbar to give the required amount of space for a combo box control.

However an EditButtons Array consisting of only ID_SEPARATORs does not allow CalcDynamicLayout to operate correctly thus loosing the advantages of deriving from CToolBar.

Has Anyone got any suggestions ? Or sample code ?



 

0
Comment
Question by:josephine
  • 2
  • 2
5 Comments
 

Author Comment

by:josephine
Comment Utility
Adjusted points to 127
0
 

Expert Comment

by:JohnWeidner
Comment Utility
Maybe you will have to override the CToolbar::CalcDynamicLayout function which you have modified to work with only separators.
0
 

Accepted Solution

by:
sem040797 earned 120 total points
Comment Utility
I would derive from CDialogBar instead. This gives you the advantage of being able to process your combo boxes just like in a modeless dialog plus gives you all the support for for the normal docking behaviors of toolbars.

Create a new dialog making its size 20 dialog units high to correspond to a normal toolbar size. Add your combo boxes. In Visual C++ 4.2, class wizard doesn't directly support CDialogBar, but I used CDialog as a base class to get my variables and messages set up then edited the code to change the derivation to CDialogBar. Be aware there is no OnInitDialog with a CDialogBar derived class. Override the Create function instead.


0
 

Author Comment

by:josephine
Comment Utility
Sem,

I have already tried deriveing from CDialogBar. My problem with that is that I cannot specify the dimensions of the dialog in pixels but only in dialog units. Making the dialog a standard 20 pixels high is impossible because I cannot draw it in pixels. If you can tell me how to set the dialog hieght at 20 pixels high and position and size the controls in pixels the points are yours.

Regards Josephine
0
 

Expert Comment

by:sem040797
Comment Utility
I'm a little unclear as to why you have to draw it. When you create a dialog bar, yor just refer to the resource ID of your dialog. The framework takes care of drawing it. Your controls are positioned using the resource editor. I merely sized the dialog so that when it was docked it didn't change the size of the toolbar, then positioned the controls where I wanted them.

If you have to move controls arround because you are resizing the dialog bar, check out article Q143255 How to Make a Resizable Dialog Bar. Basically you derive a new class from CDialogBar and override the CalcDynamicLayout and CalcFixedLayout functions. Samples are included in the article. I've also overridden the OnSize function for a CFormView dialog(with a resizable border) and used MoveWindow to reposition controls, however I've not tried this on a CDialogBar derived class.

If you really need to translate between dialog units and pixels, refer to the help on GetDialogBaseUnits(). This assumes you are using the system font for your dialog. If not, see article Q145994: How to Calculate Dialog Units When Not Using the System Font. These articles include sample code.


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now