Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

136 views
Skip to first unread message

Simon

unread,
Oct 7, 2008, 9:36:32 AM10/7/08
to
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

Bogdan

unread,
Oct 7, 2008, 2:46:50 PM10/7/08
to

"Simon" <Sim...@newsgroup.nospam> wrote in message
news:19qdna2nwZ95-HbV...@pipex.net...

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


Simon

unread,
Oct 8, 2008, 10:26:00 AM10/8/08
to
Bogdan

Thank you for that. I tried that, but it didn't solve the autosize problem.
I did notice one thing I was doing wrong which is that I was including
TBSTYLE_EX_MIXEDBUTTONS as an ordinary style flag, when it needs to be set
separately as an extended flag. Also, I hadn't been calling
InitCommonControlsEx. When I did both of those things, my toolbar looked
somewhat better, but autosizing still didn't work. However, I managed to
solve the problem (I hope!) by creating a derived class from CToolBar and
overriding CToolBar::CalcDynamicLayout. I've since encountered various
other problems with toolbars (like problems with the background colour) and
I'm working my way through those.

Simon

"Bogdan" <bog...@company.com> wrote in message
news:OPGQU0KK...@TK2MSFTNGP03.phx.gbl...

Bogdan

unread,
Oct 8, 2008, 10:45:42 AM10/8/08
to

"Simon" <Sim...@newsgroup.nospam> wrote in message
news:P_KdnVaHiu5jX3HV...@pipex.net...

> Bogdan
>
> Thank you for that. I tried that, but it didn't solve the autosize
> problem. I did notice one thing I was doing wrong which is that I was
> including TBSTYLE_EX_MIXEDBUTTONS as an ordinary style flag, when it needs
> to be set separately as an extended flag. Also, I hadn't been calling
> InitCommonControlsEx. When I did both of those things, my toolbar looked
> somewhat better, but autosizing still didn't work. However, I managed to
> solve the problem (I hope!) by creating a derived class from CToolBar and
> overriding CToolBar::CalcDynamicLayout. I've since encountered various
> other problems with toolbars (like problems with the background colour)
> and I'm working my way through those.
>
> Simon
>

I think (not 100% sure) that combination of styles _FLAT and _LIST makes the
toolbar transparent (i.e. its background only). I'm just curious why the
size of the toolbar is the problem then. You should not be able to tell its
size. Are you docking another bar just to the right of it?

Bogdan


Simon

unread,
Oct 9, 2008, 11:13:17 AM10/9/08
to
Yes I am docking a toolbar to the right of it (I have one toolbar which is
always there and others to the right that are context dependent). But the
size matters even if I don't dock anything to the right of it. Because when
the toolbar is docked it has a fixed size, and what was happening was that
as the buttons with text increased in size, the overall toolbar size did not
change (whatever I did) and the other buttons were getting pushed past the
edge of the toolbar window. Sometimes one button would be left
half-visible.

Simon


"Bogdan" <bog...@company.com> wrote in message

news:eB7XOSVK...@TK2MSFTNGP06.phx.gbl...

Jeffrey Tan[MSFT]

unread,
Oct 12, 2008, 10:21:43 PM10/12/08
to
Hi Simon,

Do you have a simple sample project to demonstrate this issue? Please also
provide the detailed steps to help us reproduce it. Once we can reproduce
it, we can understand it better and may collaborate with the product team
to help you on it. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

0 new messages