Thread: Horizontal Scroll Bars with CListBox

  1. #1
    Registered User
    Join Date
    Sep 2001

    Horizontal Scroll Bars with CListBox

    Hello, I'm using Microsoft Visual C++ 5.0, and am trying to make the horizontal scroll bars work the want I want them to for a CListBox. Here's a sample of what my code currently does:

    CListBox *listBox;
    listBox = (CListBox*)GetDlgItem(IDC_MY_LIST_BOX);
    int n;
    for (n = 0; n < 10; n++)
      listBox->AddString(text[n]);  // assume text is a char array
    When I do it this way, the horizontal scroll bar is just set to a number of pixels in width, and may scroll way too far, or not far enough. I want to it to set the horizontal scroll bar to be the width of the longest string I add to the list box. How do I determine the length in pixels of each string?

    If I don't use SetHorizontalExtent, then it won't display horizontal scroll bars for my list box, even when text scrolls off the screen to the right. If I force it to display all the scroll bars, the horizontal scroll bar just doesn't become active, even though text is still scrolling off to the right. Any ideas?
    -Grunt (Malek)

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Get the CDC of the list box and call CDC::GetOutputTextExtent().


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scroll Bars Are Scrolling Me Crazy
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 03-03-2006, 01:43 PM
  2. Enabling horizontal scroll bar in dialog list box
    By bennyandthejets in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2004, 06:54 PM
  3. Scroll Bars and Focus
    By Thantos in forum Windows Programming
    Replies: 1
    Last Post: 08-21-2003, 11:57 AM
  4. Scroll Bars
    By bc17 in forum Windows Programming
    Replies: 2
    Last Post: 02-21-2003, 03:15 PM
  5. no horizontal scroll bar?
    By scott27349 in forum C++ Programming
    Replies: 0
    Last Post: 03-16-2002, 10:41 PM