Horizontal Scroll Bars with CListBox

This is a discussion on Horizontal Scroll Bars with CListBox within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I'm using Microsoft Visual C++ 5.0, and am trying to make the horizontal scroll bars work the want I ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    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:

    Code:
    CListBox *listBox;
    listBox = (CListBox*)GetDlgItem(IDC_MY_LIST_BOX);
    int n;
    
    listBox->SetHorizontalExtent(500);
    
    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
    Posts
    4,630
    Get the CDC of the list box and call CDC::GetOutputTextExtent().

    gg

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, 12: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, 02:15 PM
  5. no horizontal scroll bar?
    By scott27349 in forum C++ Programming
    Replies: 0
    Last Post: 03-16-2002, 09:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21