This documentation is archived and is not being maintained.


Retrieves from the list box the width in pixels by which it can be scrolled horizontally.

int GetHorizontalExtent( ) const;

The scrollable width of the list box, in pixels.

This is applicable only if the list box has a horizontal scroll bar.

// The pointer to my list box.
extern CListBox* pmyListBox;

// Find the longest string in the list box.
CString str;
CSize   sz;
int     dx=0;
CDC*    pDC = pmyListBox->GetDC();
for (int i=0;i < pmyListBox->GetCount();i++)
   pmyListBox->GetText( i, str );
   sz = pDC->GetTextExtent(str);

   if ( > dx)
      dx =;

// Set the horizontal extent only if the current extent is not large enough.
if (pmyListBox->GetHorizontalExtent() < dx)
   ASSERT(pmyListBox->GetHorizontalExtent() == dx);