Vertical and Horizontal Scroll Bars in Owner Drawn ListBox

Started by Ratch, October 11, 2006, 05:08:43 PM

Previous topic - Next topic

Ratch

To the Ineffable All,

     I cannot get my owner-drawn listbox to produce either a V or H scrollbar, even when I  process the WM_MEASUREITEM message.  Of course I have the WS_VSCROLL and WS_HSCROLL styles selected.  Do I have to make my own scrollbar window?  I hope not.   Ratch

PBrennick

Ratch,
That was the way I did it.  Others way have another way.


;---------- [Create the VScroll Control] ----------
         invoke     CreateWindowEx, NULL, addr ScrollClass, NULL,\
                    WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS or SBS_VERT,\
                    523, 28, 14, 316, hwnd, 2001, hInst, NULL
            mov     hScrollV, eax

;---------- [Create the HScroll Control] ----------
         invoke     CreateWindowEx, NULL, addr ScrollClass, NULL,\
                    WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS or SBS_HORZ,\
                    25, 336, 467, 14, hwnd, 2002, hInst, NULL
            mov     hScrollH, eax


Paul
The GeneSys Project is available from:
The Repository or My crappy website

Ratch

PBrennick,

     Sure, I know how to do a scrollbar window, but I was hoping that the functionality was built in so I would not have to do so.  What good is WM_MEASUREITEM if windows does not use it to determine whether the listbox has overflowed and needs a scrollbar?  Ratch

Tedd

if (SendMessage(hListView,LVM_GETCOUNTERPAGE,0,0) < SendMessage(hListView,LVM_GETITEMCOUNT,0,0)) you_need_a_vertical_scrollbar();

As for getting it to draw, if it's owner-drawn then yeah I think you have to draw it yourself. Unless you can manage to get the handle and explicitly cause it to redraw.






Edit: "<" not ">" :lol
No snowflake in an avalanche feels responsible.

Ratch

Tedd,

     So what is WM_MEASUREITEM good for then?  Ratch

Tedd

To give you the dimensions (width and height, in pixels) of the owner-drawn control, so you can draw it?
No snowflake in an avalanche feels responsible.

Ratch

Tedd,

QuoteTo give you the dimensions (width and height, in pixels) of the owner-drawn control, so you can draw it?

     No, I already know those dimensions. After all, I coded it.  I thought it is used to tell to the owner window the height and width of the items to be placed in the listbox.  Then the owner window can call for a scrollbar in the listbox when the items overflow.  Ratch

PBrennick

Ratch,
I understand your frustration. It almost seems as if they had an idea but then nerver finished it. Typical.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

Tedd

WM_MEASUREITEM is used for all kinds of controls though, not just listviews. The dimensions are given because some controls are resizable, or their size can't be known in advance, or is in dialog units, etc. Even if you 'know' the size already, you should probably use the sizes given to you rather than the ones you expect :P

Apparently, for ownerdraw-listbox it's sent once for each item to be drawn (rather than once for the entire control.) I assume the scrollbar will still be created as necessary, so there's no need for you to do that; getting it to draw though, might be a different matter.

I might have a play with it a bit later and see what I come up with :wink there'll be a way to do it, even if it's not very pretty :bdg
No snowflake in an avalanche feels responsible.

Ratch

Tedd,

QuoteThe dimensions are given because some controls are resizable, or their size can't be known in advance, or is in dialog units, etc. Even if you 'know' the size already, you should probably use the sizes given to you rather than the ones you expect

     WM_MEASUREITEM is for the items inserted into the controls, not the control itself.  Item height and item width are the only size parameters in MEASUREITEMSTRUCT.  I have been processing WM_MEASUREITEM, but the item height is already filled in with what it should be.  The item width is not used by listboxes.  At least I return a TRUE status back to Windows to show I processed it, because the documentation says I should.

QuoteApparently, for ownerdraw-listbox it's sent once for each item to be drawn (rather than once for the entire control.) I assume the scrollbar will still be created as necessary, so there's no need for you to do that; getting it to draw though, might be a different matter.

     WM_MEASUREITEM is sent only once after the first LB_ADDSTRING for a LBS_OWNERDRAWFIXED listbox, and sent repeatedly for LB_ADDSTRING  to a LBS_OWNERDRAWVARIABLE listbox.  If I use the LBS_DISABLENOSCROLL style, then  V & H scrollbars without the thumbs appear, which is of course useless.  I might try playing around with subclassing the listbox today.  When I Google this problem, I get oodles of examples of what I want to do, but they are all written is .NET or VB or MFC which I cannot translate into MASM because they make calls to libraries and use constants that I never heard of.  Any help you can give me is appreciated.  Ratch


Ratch

To the Ineffable All,
     Well, I pretty well solved my problem.  I jumped into learning listview controls, and they are slick.  No more problems with scrollbars.  The LIST_REPORT style automatically puts in scrollbars when either the vertical or horizontal image size becomes too large to show in the window.  There is a bit of a learning curve to using listview controls, but at least they appear to follow the documentation.  Also, they are rich in features.  So for me, it is good-bye listbox, hello listview.  Ratch