This documentation is archived and is not being maintained.

CComboBox::GetHorizontalExtent 

Retrieves from the combo box the width in pixels by which the list-box portion of the combo box can be scrolled horizontally.


UINT GetHorizontalExtent( ) const;

The scrollable width of the list-box portion of the combo box, in pixels.

This is applicable only if the list-box portion of the combo box has a horizontal scroll bar.

// The pointer to my combo box.
extern CComboBox* pmyComboBox;

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

   if (sz.cx > dx)
      dx = sz.cx;
}
pmyComboBox->ReleaseDC(pDC);

// Set the horizontal extent only if the current extent is not large enough.
if (pmyComboBox->GetHorizontalExtent() < dx)
{
   pmyComboBox->SetHorizontalExtent(dx);
   ASSERT(pmyComboBox->GetHorizontalExtent() == dx);
}
Show: