Re: scroll-wheel problems with an owner-draw ListBox

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 01/15/05


Date: Fri, 14 Jan 2005 19:57:09 -0600

me wrote:

>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++


Relevant Pages

  • Re: Scrollbar thumbtrack doesnt scroll all the way
    ... SetWindowPos in regards to an embedded child window. ... Note also that OnSize is ... The size of the scroll bar in between is largely irrelevant to ... The correct value is to use nPos. ...
    (microsoft.public.vc.mfc)
  • Re: Scrollbar thumbtrack doesnt scroll all the way
    ... SetWindowPos in regards to an embedded child window. ... Note also that OnSize is ... The size of the scroll bar in between is largely irrelevant to ... The correct value is to use nPos. ...
    (microsoft.public.vc.mfc)
  • Re: GDI+ Custom Control
    ... I have actually done this already; my first MFC program was a medical data display and I ... First, I would treat each of the "tiles" as being a separate window, each a child window ... You scroll the tile. ... So there would be one "tile" for Heart ...
    (microsoft.public.win32.programmer.gdi)
  • Re: XSun: Slow Scroll
    ... Display being veryslowto scroll even the terminal in windowing ... CDE) and what framebuffer. ... a PCI card somewhere in the system. ... If you're running Gnome as your window manager, ...
    (comp.sys.sun.hardware)
  • Re: problems restoring previous scrollbar/window position with CListBox (newbie alert)
    ... It "kind of" works - The ListBox window will scroll to a position where the ... Using SelectString doesn't do this, in fact if an item is selected and then ...
    (microsoft.public.vc.mfc)