Results 1 to 11 of 11

Thread: List box control

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    27
    Tricky one for those that think they are GUI experts. How do you get a listbox to scroll horizontally.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well, it needs to be done when the control is initialised, by using the WS_HSCROLL window style. Unfortunately, it can't be changed after it's been created. If a new list box was created, then it could be used that way. I'll try knocking up a more useful list box and get back to you.

    [Edited by parksie on 08-03-2000 at 03:59 PM]
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Const LB_SETHORIZONTALEXTENT = &H194 'Used in the SendMessage function
    
    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Any) As Long
    
    
    Private Sub Form_Load()
       dim x
       X = SendMessage(List1.hwnd, LB_SETHORIZONTALEXTENT, 350, 0) 'Win API function to set the scrollbar
    
       List1.AddItem ":DFJKD:JFLSDJFDSJFL:DSLF:JDSFJLSDJFLSDJFLSJLFDSFJLSDJFLDSJLKF"
    End Sub
    [Edited by HeSaidJoe on 08-03-2000 at 04:15 PM]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Doesn't work. The problem is with the window style, I think.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    27
    Thanks!

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    works fine on my pc...what are you running?
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    27
    I just found a MS KB article on it, using your same method.

    Option Explicit

    Private Declare Function SendMessageByNum Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
    wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Const LB_SETHORIZONTALEXTENT = &H194

    Private Sub Command1_Click()
    Dim s As String
    Static x As Long
    s = InputBox("Please enter any text", "List scroll", _
    "this is a simple scrollbar sample for demonstration purposes")
    List1.AddItem s
    If x < TextWidth(s & " ") Then
    x = TextWidth(s & " ")
    If ScaleMode = vbTwips Then _
    x = x / Screen.TwipsPerPixelX ' if twips change to pixels
    SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, x, 0
    End If
    End Sub

  8. #8
    Guest
    It should work:

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const LB_SETHORIZONTALEXTENT = &H194
    
    Private Sub Command1_Click()
        Call SendMessage(List1.hwnd, LB_SETHORIZONTALEXTENT, 350, 0)
    End Sub

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    swine's KB method works...

    HeSaidJoe: W98/PIII/VB5 Enterprise
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Parksie:
    weird stuff
    ...Megatron has exactly the same code and he is running VB5 and it works for him, so it should work on yours too...
    I'm running 6...
    OH..well, long as swine is happy and it works for him.

    Later.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You're right. He needs it, and it works for him. That's all we're concerned about here. Although why it doesn't work on mine needs checking...I'll see what the problem is.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width