Sets the tab-stop positions in a list box.

void SetTabStops( ); 
BOOL SetTabStops( 
   const int& cxEachStop  
BOOL SetTabStops( 
   int nTabStops, 
   LPINT rgTabStops  


Tab stops are set at every cxEachStop dialog units. See rgTabStops for a description of a dialog unit.


Specifies the number of tab stops to have in the list box.


Points to the first member of an array of integers containing the tab-stop positions in dialog units. A dialog unit is a horizontal or vertical distance. One horizontal dialog unit is equal to one-fourth of the current dialog base width unit, and one vertical dialog unit is equal to one-eighth of the current dialog base height unit. The dialog base units are computed based on the height and width of the current system font. The GetDialogBaseUnits Windows function returns the current dialog base units in pixels. The tab stops must be sorted in increasing order; back tabs are not allowed.

Nonzero if all the tabs were set; otherwise 0.

To set tab stops to the default size of 2 dialog units, call the parameterless version of this member function. To set tab stops to a size other than 2, call the version with the cxEachStop argument.

To set tab stops to an array of sizes, use the version with the rgTabStops and nTabStops arguments. A tab stop will be set for each value in rgTabStops, up to the number specified by nTabStops.

To respond to a call to the SetTabStops member function, the list box must have been created with the LBS_USETABSTOPS style.

// Find the pixel width of the largest first substring.
CString str;
CSize   sz;
int     nIndex, dx = 0;
CDC*    pDC = myListBox.GetDC();
for (int i = 0; i < myListBox.GetCount(); i++)
   myListBox.GetText( i, str );

   if ((nIndex = str.Find('\t')) != -1)
      str = str.Right(nIndex);

   sz = pDC->GetTextExtent(str);

   if ( > dx)
      dx =;

// Set tab stops at every one and 1/3 units 
// of the largest string.  
// NOTE: Convert pixels to dialog units.
myListBox.SetTabStops((dx*4/3 * 4) / LOWORD(::GetDialogBaseUnits()));

Header: afxwin.h