TabStops.exe Sets Tab Stops in a Windows List Box (66652)



The information in this article applies to:

  • Microsoft Platform Software Development Kit (SDK) 1.0
  • Microsoft Windows Software Development Kit (SDK) 3.1

This article was previously published under Q66652

SUMMARY

Tab stops can be used in a list box to align columns of information. This article describes how to set tab stops in a list box and provides a code example that demonstrates the process.

There is a sample application named TABSTOPS in the Microsoft Download Center that demonstrates how tab stops are set and used in a list box.

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
To set tab stops in a list box, perform the following three steps:
  1. Specify the LBS_USETABSTOPS style when creating the list box.
  2. Assign the desired tab stops to an integer array.
    1. The tab stop values must be in increasing order -- back tab stops are not allowed. The tabs work the same as typewriter tabs: once a tab stop is overrun, a tab character will move the cursor to the next tab stop. If the tab stop list is overrun (that is, the current position is greater than the last tab stop value), the default tab of eight characters is used.
    2. The tab stops should be specified in dialog units. On the average, each character is about four horizontal dialog units in width.
    3. It is possible to hide columns of text from the user by specifying tab stops beyond the right side of the list box. This can be a useful way to hide information used for the application's internal processing.
  3. Send an LB_SETTABSTOPS message to the list box to set the tab stops. For example, in Windows 3.1:
          SendMessage(GetDlgItem(hDlg, IDD_LISTBOX),
                      LB_SETTABSTOPS,
                      TOTAL_TABS,
                      (LONG)(LPSTR)TabStopList);
    
    					
    1. If wParam is set to 0 (zero) and lParam to NULL, the tab stops are set to two dialog units by default.
    2. SendMessage() will return TRUE if all of the tab stops are set successfully; otherwise, SendMessage() returns FALSE.

Example

Below is an example of the process. Tab stops are set at character positions 16, 32, 58, and 84.
   int     TabStopList[TOTAL_TABS]; /*  Array to store tabs */ 

   TabStopList[0] = 16 * 4;          /* 16 spaces */ 
   TabStopList[1] = 32 * 4;          /* 32 spaces */ 
   TabStopList[2] = 58 * 4;          /* 58 spaces */ 
   TabStopList[3] = 84 * 4;          /* 84 spaces */ 

   SendMessage(GetDlgItem(hDlg, IDD_LISTBOX),
               LB_SETTABSTOPS,
               TOTAL_TABS,
               (LONG)(LPSTR)TabStopList);
				
NOTE: For Win32, use LPARAM instead of LONG.

If the desired unit of measure is character position, then specifying tab positions in dialog units is recommended. Dialog units are independent of the current font; they are loosely based on the average width of the system font. Each character takes approximately four dialog units.

NOTE: Under Windows 95, dialog base units for dialogs based on non-system fonts are calculated in a different way than under Windows 3.1. For more information, please see the following article in the Microsoft Knowledge Base:

125681 How to Calculate Dialog Base Units with Non-system-based Font

For more control over the exact placement of a tab stop, the desired position should be converted to a pixel offset and this offset should be converted into dialog units. The following formula will take a pixel position and convert it into the first tab stop position before (or at) the desired pixel position:
   TabStopList[n] = 4 * DesiredPixelPosition / 
                     LOWORD(GetDialogBaseUnits());
				

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbdownload kbCtrl kbfile kbinfo kbListBox kbSample KB66652 kbAudDeveloper