Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Expertise: Beginner
Aug 20, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Setting Tab Stops in List Boxes

To quickly set tab stops in list boxes, use the SendMessage API call. The units used are called Dialog Base Units, which average out to about four per character. Some experimentation is required to get the settings just right, but from then on it's easy. Here's an example subroutine that sets three tab stops in a standard list box:
 Declare Function SendMessage Lib "User" _ 
(ByVal hWnd As Integer, ByVal wMsg As Integer, _ 
ByVal wParam As Integer, lParam As Any) As Long 
Global Const WM_USER = &H400 
Global Const LB_SETTABSTOPS = (WM_USER + 19) 
Sub SetTabs (Lst As ListBox) 
ReDim Tabs(0 To 2) As Integer 
Dim Rtn& 
Tabs(0) = 70 
Tabs(1) = 120 
Tabs(2) = 160 
Rtn = SendMessage(Lst.hWnd, LB_SETTABSTOPS, _ 
3, Tabs(0)) 
End Sub 
Use the API's GetDialogBaseUnits function to calculate the number of units required for a given string. The function's return value contains a number that is four times the average character width of the system font. Thus, to find the width in dialog base units of a string (A$), use the following code:
 Declare Function GetDialogBaseUnits& Lib "User" ()

DBU& = GetDialogBaseUnits&() 
'Extract low word (character width) 
W% = DBU& And &HFFFF& 
'Calculate width of A$ in dialog base units 
DBUWidth% = (Len(A$) * W%) \ 4 
Karl E.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date