Re: Can't autosize CToolbar object, using TB_AUTOSIZE or any other way

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Simon" <Simon2@xxxxxxxxxxxxxxxx> wrote in message
news:19qdna2nwZ95-HbVnZ2dneKdnZydnZ2d@xxxxxxxxxxxx
I want to have a flat toolbar with text showing to the right of some
buttons, but not all. I can achieve this with CToolbar by creating it
with
CreateEx with the style TBSTYLE_FLAT | TBSTYLE_LIST |
TBSTYLE_EX_MIXEDBUTTONS which
allows me to set button text to the right of some buttons without having
to do it to all of them. I then
load the toolbar bitmap by calling LoadToolbar and finally I call
TBSTYLE_AUTOSIZE on each button (otherwise they would all have the same
size even without text) and
I call CToolBar::SetButtonText to set the text for those buttons that I
want to have text
showing.

This sort of works. Some buttons seem a little off-centre (even without
text) which I don't understand and a separator gets a gap after it that is
much too big - again, I don't know why. But much more seriously, the
overall
toolbar retains the size it would have had if I hadn't added the text to
some buttons. I have tried using SendMessage to send the TB_AUTOSIZE
message to the toolbar (and/or its ctrl) or calling the AutoSize function
on
CToolBarCtrl(), but they have no effect at all.

I can't work out what I need to do. I have tried experimenting with
flags,
every way I can think. Nothing works. Calling
CMainFrame::RecalcLayout(),
resizing the main frame, etc - none of these things make any difference.
I've tried everything I can think of.

Any help with this would be very much appreciated.

Simon



I'm assuming that you are docking the bar horizontally (i.e. top or bottom).
I have used that kind of bars in the past but docked them vertically so all
of the buttons had the same size - I called SetSizes() to achieve it.

One of the things you could try is to call SetButtonInfo() with
BTN_SHOWTEXT|TBSTYLE_AUTOSIZE on buttons with text and TBSTYLE_AUTOSIZE on
buttons without text. That should work. Make sure to get rid of all the
other calls that you have mentioned. All of that should be possible without
using the embedded control (i.e. use only CToolBar).

Bogdan


.


Quantcast