Discussion:
scroll-wheel problems with an owner-draw ListBox
(too old to reply)
me
2005-01-14 20:14:15 UTC
Permalink
Hi, i've written an owner-draw ListBox but I get some strange effects when
using the scroll-wheel to scroll the window.

If I set the type to "Fixed" the scroll-wheel causes the window to scroll
correctly but for some reason my MeasureItem function never gets called and
the items in the listbox are the wrong height (they just use some kind of
default value).

If I set the type to "Variable" the MeasureItem function gets called for
every item as expected and the listbox looks correct (all items are the
correct height). But when I use the scroll-wheel to scroll the window it
always scrolls downwards one whole page before stopping at the correct
window position.

A friend said that he might have seen this scroll behavior on some other
windows applications - is this a known problem? How come my MeasureItem
function doesn't get called (not even once) when the owner-draw type is set
to "Fixed"?

Is there a function I can call to set the "fixed" height manually?

Any help greatly appreciated!

Karl.
Doug Harrison [MVP]
2005-01-15 01:57:09 UTC
Permalink
Post by me
Hi, i've written an owner-draw ListBox but I get some strange effects when
using the scroll-wheel to scroll the window.
If I set the type to "Fixed" the scroll-wheel causes the window to scroll
correctly but for some reason my MeasureItem function never gets called and
the items in the listbox are the wrong height (they just use some kind of
default value).
If I set the type to "Variable" the MeasureItem function gets called for
every item as expected and the listbox looks correct (all items are the
correct height). But when I use the scroll-wheel to scroll the window it
always scrolls downwards one whole page before stopping at the correct
window position.
A friend said that he might have seen this scroll behavior on some other
windows applications - is this a known problem? How come my MeasureItem
function doesn't get called (not even once) when the owner-draw type is set
to "Fixed"?
Is there a function I can call to set the "fixed" height manually?
Any help greatly appreciated!
Below are excerpts from some past messages I've written on these topics:

***** About LBS_OWNERDRAWFIXED

You can set LBS_OWNERDRAWFIXED in the
resource editor, ignore the initial WM_MEASUREITEM sent to your dialog
box, and fix things up in OnInitDialog with CListBox::SetItemHeight.
Windows appears to reliably provide a default height for
WM_MEASUREITEM, but if you feel really strongly about setting it, you
can override your dialog class's WindowProc and handle the message
there.

In my OnInitDialog handlers, I have code that sets the height using that
SetItemHeight and follows it by a function that resizes the listbox if the
"integral height" style is set. So I need to use two extra function calls to
make LBS_OWNERDRAWFIXED work right.

***** About funky listbox animation

I'd avoid LBS_OWNERDRAWVARIABLE if possible, as it suffers a weird bug in
Win2K and XP, when "smooth scrolling of listboxes" is activated (TweakUI
calls it "Enable list box animation"), in which rolling the wheel causes
the listbox to visually scroll in the "opposite" direction though the right
item is brought into view. A user reported this in one of my apps, and I
cured it by switching to LBS_OWNERDRAWFIXED. See this message for another
report by a C# user:

http://groups.google.com/groups?selm=v8n7sqjq14k41a%40corp.supernews.com
--
Doug Harrison
Microsoft MVP - Visual C++
me
2005-01-15 18:14:08 UTC
Permalink
Doug, you've diagnosed my problem exactly!

Many thanks,

Karl.
Post by Doug Harrison [MVP]
Post by me
Hi, i've written an owner-draw ListBox but I get some strange effects when
using the scroll-wheel to scroll the window.
If I set the type to "Fixed" the scroll-wheel causes the window to scroll
correctly but for some reason my MeasureItem function never gets called and
the items in the listbox are the wrong height (they just use some kind of
default value).
If I set the type to "Variable" the MeasureItem function gets called for
every item as expected and the listbox looks correct (all items are the
correct height). But when I use the scroll-wheel to scroll the window it
always scrolls downwards one whole page before stopping at the correct
window position.
A friend said that he might have seen this scroll behavior on some other
windows applications - is this a known problem? How come my MeasureItem
function doesn't get called (not even once) when the owner-draw type is set
to "Fixed"?
Is there a function I can call to set the "fixed" height manually?
Any help greatly appreciated!
***** About LBS_OWNERDRAWFIXED
You can set LBS_OWNERDRAWFIXED in the
resource editor, ignore the initial WM_MEASUREITEM sent to your dialog
box, and fix things up in OnInitDialog with CListBox::SetItemHeight.
Windows appears to reliably provide a default height for
WM_MEASUREITEM, but if you feel really strongly about setting it, you
can override your dialog class's WindowProc and handle the message
there.
In my OnInitDialog handlers, I have code that sets the height using that
SetItemHeight and follows it by a function that resizes the listbox if the
"integral height" style is set. So I need to use two extra function calls to
make LBS_OWNERDRAWFIXED work right.
***** About funky listbox animation
I'd avoid LBS_OWNERDRAWVARIABLE if possible, as it suffers a weird bug in
Win2K and XP, when "smooth scrolling of listboxes" is activated (TweakUI
calls it "Enable list box animation"), in which rolling the wheel causes
the listbox to visually scroll in the "opposite" direction though the right
item is brought into view. A user reported this in one of my apps, and I
cured it by switching to LBS_OWNERDRAWFIXED. See this message for another
http://groups.google.com/groups?selm=v8n7sqjq14k41a%40corp.supernews.com
--
Doug Harrison
Microsoft MVP - Visual C++
Loading...