We recommend using Visual Studio 2017
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.

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

   if (sz.cx > dx)
      dx = sz.cx;

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

Header: afxwin.h