News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Help needed with vertical toolbars

Started by NoCforMe, April 15, 2015, 01:42:45 PM

Previous topic - Next topic

NoCforMe

OK, so my latest mini-obsession is trying to create a working vertical toolbar. I have a small testbed that sorta works (attached below); it shows the toolbar, which is functional.

The problem I'm having is sizing the damn thing correctly. No matter what I've tried, I cannot get it to the proper size, except by simple brute force (resizing the toolbar window explicitly).

What the testbed does is use a bunch of messages to get various pieces of size information about the toolbar and write them to a log file. I'm feeding it a bitmap with 24x24 images, and setting the bitmap size to this via TB_SETBITMAPSIZE. There are 8 buttons. Here's what I get:
TB_GETBUTTONSIZE says width=96, height=30
TB_GETPADDING says x-padding=7, y-padding=6
TB_GETMAXSIZE says width=96, height=240
TB_GETRECT says left=0, right=32, top=2, bottom=32
TB_GETITEMRECT says left=0, right=32, top=2, bottom=32
TB_GETROWS says # rows=9

I really don't understand much of what's going on here. None of these results make much sense, and I can't get any of them to combine in such a way as to give me a reasonably-sized toolbar. (I did resize the toolbar window by hand, using WinSpy, and found 36x246 to be a good size.)

I'm especially puzzled by the TB_GETBUTTONSIZE results; where does that width of 96 pixels come from?

There's another toolbar message available, according to MSDN, but I didn't use it because it's not in the MASM include file: TB_GETMETRICS returns a TBMETRICS structure, which returns some padding/spacing values.

Also take a look at what TB_GETROWS shows: 9 rows? Does this include a separator or something?

I'm just trying to create a simple vertical toolbar. I would rather not mess with subclassing or rebars or anything fancy-schmancy like that. I'd appreciate any help making sense of this stuff.

Oh, here's something else: regarding styles, I used the CCS_NORESIZE style, about which MSDN has this to say:
QuotePrevents the control from using the default width and height when setting its initial size or a new size. Instead, the control uses the width and height specified in the request for creation or sizing.
All I know is that if I omit this style, the toolbar gets very wide and extends to the bottom of the parent window.
Assembly language programming should be fun. That's why I do it.

dedndave

you can add the following to your project include file

IFNDEF TB_GETMETRICS
  TB_GETMETRICS EQU WM_USER + 101
ENDIF

IFNDEF TB_SETMETRICS
  TB_SETMETRICS EQU WM_USER + 102
ENDIF

IFNDEF TBMETRICS
  TBMETRICS       STRUCT
    cbSize          DWORD ?
    dwMask          DWORD ?
    cxPad           DWORD ?
    cyPad           DWORD ?
    cxBarPad        DWORD ?
    cyBarPad        DWORD ?
    cxButtonSpacing DWORD ?
    cyButtonSpacing DWORD ?
  TBMETRICS       ENDS
ENDIF


from what i understand, these messages are supported for Vista and up
or, with XP if a manifest and common controls 6 is used
not supported for win2000

NoCforMe

I tried TB_GETMETRICS, got garbage. I suppose that's because I didn't supply a manifest. (To be honest, I really don't want to mess with manifests either, so that's pretty much the end of that.)

Any other ideas?
Assembly language programming should be fun. That's why I do it.

dedndave

well - my first thought was that they are measured in "dialog units" or "dialog base units"
but, according to the documentation, that doesn't seem to be the case - it clearly says "pixels"

not having played with toolbars much, i figured i'd leave it to someone who has
i generally make my own tool box areas - with custom buttons, etc...

dedndave

not having a manifest - and not using InitCommonControlsEx - may very well be the whole problem   :t

NoCforMe

I did use InitCommonControlsEx(), using ICC_BAR_CLASSES (which should cover toolbars). Probably no manifest is the problem. (But by "problem" I mean the problem with using TB_GETMETRICS, not the toolbar-sizing problem in general.)

Nowhere in the MSDN documentation on toolbars I've read does it say anything about needing a manifest to create a simple toolbar.
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: MSDN
TB_GETMETRICS message
Note  To use this message, you must provide a manifest specifying Comclt32.dll version 6.0.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb787342%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

NoCforMe

Yes, you need a manifest to use TB_GETMETRICS. That's not what I want to do; I just want a working vertical toolbar, and I don't believe that message is essential for one. As I said, nowhere in the MSDN docs (that I've seen so far) does it say anything about needing a manifest to create a vertical toolbar.

I don't even really know what the information returned by that message means, or if it will even help me create a decent toolbar.

Can't believe nobody here has a working recipe for this. How about the author of ResEd, the resource editor; does he hang out here? I'd actually like to create a toolbar just like the one in that program.
Assembly language programming should be fun. That's why I do it.

dedndave

the fact that it is vertical probably doesn't change the code all that much

some time ago, Hutch made a nice toolbar demo program
but, you're not going to like it
i'm pretty sure i remember him mentioning common controls v6 (manifest, InitCommonControlsEx with specific flags set)

i don't understand your dislike for manifests or common controls 6
but, that's your choice to make   :t

hutch--

> Can't believe nobody here has a working recipe for this.

The problem is you have a working recipe for making the system defined capacity fail. If you want to use later capacity like a rebar with a toolbar in it, then start using a manifest and version control block. The app is technically trivial to make, supports RGBA images with transparent backgrounds and is highly adjustable to get the right appearance.

NoCforMe

Didn't you read what I wrote? I don't want a rebar, just a vertical toolbar. Are you saying that's the only way to do a working vertical toolbar? And I said nothing fancy; don't care about transparent backgrounds, etc.

If you have some code that works, I'd appreciate a peek at it.
Assembly language programming should be fun. That's why I do it.

NoCforMe

Despite the relative lack of help here (thanks for trying, folks, but it didn't do my problem much good), I made a small discovery which might be useful for others to know about:

Before getting all those measurements (using TB_GETPADDING, etc.) I set up the tooltips by issuing the following:

INVOKE SendMessage, ToolbarHandle, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS

It turns out that this significantly changes the results returned by TB_GETMAXSIZE, in particular the maximum width of the toolbar. Which makes perfect sense once I thought about it: in order to add text to a toolbar button, you're going to need more space than just for an image. TBSTYLE_EX_MIXEDBUTTONS lets you mix graphic and textual buttons in the toolbar. (It's also the magic incantation that enables tooltips.)

So I delayed sending this until after getting the dimensional information. I took the results from TB_GETMAXSIZE and TB_GETPADDING and added them together, then used this to size the control. While not perfect, it's adequate for the moment. Hopefully I'll be able to tweak it later, perhaps after someone here better explains what's going on here.

Oh, and it seems that the TB_GETPADDING values apply to the entire control (toolbar), not to each individual button. The docs don't really explain that very well.
Assembly language programming should be fun. That's why I do it.

hutch--

Well, its reasonably simple, if you want it to look like crap, you can place buttons down the left side of the window. Slightly more up market is to position a toolbar on the left side and restrict its width so it displays vertically but then you must match the image backgrounds to whatever the backgrounds for the window are or the look like real crap. You have variations like using a child window and place the toolbar in the child window and use the background colour of the child window to match what you put in the image background.

The reason why you use a version 6 common control manifest is so you can avoid all the messing around trying to make the buttons look OK on a toolbar. You can use anything from 16 colour to RGB-Alpha and it will have the correct appearance. The assumption that you can use sloppy shortcuts to bypass the OS design will not work for you here. The common controls are no joy to work with but writing alternatives is an even bigger pig to manage.

I have attached the test piece to make proper XP and later vertical toolbars.

NoCforMe

Thanks, I'll study that.

It does look good.
Assembly language programming should be fun. That's why I do it.

Gunther

Hi Hutch,

thank you for the example. Do I remeber right? Did you post a similar example in the old forum? I couldn't find it.

Gunther
You have to know the facts before you can distort them.