Solved

Horizontal Scroll for listbox

Posted on 1998-09-30
10
382 Views
Last Modified: 2012-06-22
Anyone have the code for horizontal scroll in listbox?  I think there is an API to determine this.


Specialist
0
Comment
Question by:SPECIALIST
10 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1437433
Public Const LB_SETHORIZONTALEXTENT = &H194

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Long) As Long


Public Sub AddHScrollToListBox(ByVal FormWithControl As Form, ByVal ListBox As Control, ByVal FullString As String)

  Dim ListHwnd As Long
  Static GreatestWidth As Long

  ' Get Focus of the ListBox to Make A Horizontal Scroll Bar For '
  ListBox.SetFocus
  ListHwnd = GetFocus()

  If FormWithControl.TextWidth(FullString) > GreatestWidth Then

    ' Add/Change Size of Horizontal Scroll Bar '
    Call SendMessage(ListHwnd, LB_SETHORIZONTALEXTENT, FormWithControl.TextWidth(FullString), NUL)
    GreatestWidth = FormWithControl.TextWidth(FullString)
    DoEvents

  End If

End Sub


0
 
LVL 3

Author Comment

by:SPECIALIST
ID: 1437434
Thanks I just have one error Getfocus says "sub or function not defined"

Just need that sub!

Specialist
0
 
LVL 1

Accepted Solution

by:
CarlosJac earned 50 total points
ID: 1437435
Declare Function GetFocus Lib "user32" Alias "GetFocus" () As Long

0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 10

Expert Comment

by:viktornet
ID: 1437436
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
     (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
     ByRef lParam As Long) As Long

const LB_SETHORIZONTALEXTENT = 404

dim s as long

s = SendMessage(ListBox1.hWnd, LB_SETHORIZONTALEXTENT, 500, 0)

//Can you do like this in VB???->>> ListBox1.hWnd

Regards,
Viktor Ivanov
0
 
LVL 7

Expert Comment

by:tward
ID: 1437437
Sorry about that, forgot the one declaration.  I would have posted it but someone beat me to it...
0
 
LVL 3

Author Comment

by:SPECIALIST
ID: 1437438
tward,

sorry I know you answered first, but I asked for clarification, after a few hours I had to re-post due to time limitations.

Sorry!
Specialist

0
 
LVL 3

Author Comment

by:SPECIALIST
ID: 1437439
One other thing, what is the 3rd argument?  fullstring as string?

should be ok after that!

Thanks
0
 
LVL 7

Expert Comment

by:tward
ID: 1437440
The function I did gets called after anything is added to the Listbox so I pass the string that was added and try to calculate the size of the Scroll bar based on the Text that was added.
0
 
LVL 3

Author Comment

by:SPECIALIST
ID: 1437441
Thanks!
0
 
LVL 1

Expert Comment

by:Vingamel
ID: 2509106
Can somebody provide an example of calling this API function?  Thanks.
--Vingamel
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 78
Access query that references subform 5 47
passing a value with stream reader AFTER a ";" 3 66
Excel Automation VBA 19 68
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question