devxlogo

Setting Tab Stops in List Boxes

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 aboutfour per character. Some experimentation is required to get the settingsjust right, but from then on it’s easy. Here’s an example subroutine thatsets 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 numberof units required for a given string. The function’s return value containsa 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 thefollowing 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 
See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist