Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Deriving from CToolBar

Posted on 1997-04-05
5
Medium Priority
?
504 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
[X]
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
  • 2
  • 2
5 Comments
 

Author Comment

by:josephine
ID: 1300867
Adjusted points to 127
0
 

Expert Comment

by:JohnWeidner
ID: 1300868
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 360 total points
ID: 1300869
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
ID: 1300870
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
ID: 1300871
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

688 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