CComboBox::SetHorizontalExtent

너비를 콤보 상자의 목록 상자 부분에서 가로로 스크롤할 수 픽셀 단위로 설정 합니다.

void SetHorizontalExtent( 
   UINT nExtent  
);

매개 변수

  • nExtent
    콤보 상자의 목록 상자 부분에서 가로로 스크롤할 수 픽셀 수를 지정 합니다.

설명

목록 상자의 너비를이 값 보다 작은 경우 항목 목록 상자에 가로 스크롤 막대가 가로로 스크롤됩니다. 목록 상자의 너비를 같거나이 값 보다 큰 경우 가로 스크롤 막대가 숨겨집니다 또는 콤보 상자에 있는 경우는 CBS_DISABLENOSCROLL 스타일을 사용 하지 않도록 설정 합니다.

예제

// Find the longest string in the combo box.
CString     str;
CSize       sz;
int         dx = 0;
TEXTMETRIC  tm;
CDC*        pDC = m_pComboBox->GetDC();
CFont*      pFont = m_pComboBox->GetFont();

// Select the listbox font, save the old font
CFont* pOldFont = pDC->SelectObject(pFont);
// Get the text metrics for avg char width
pDC->GetTextMetrics(&tm);

for (int i = 0; i < m_pComboBox->GetCount(); i++)
{
   m_pComboBox->GetLBText(i, str);
   sz = pDC->GetTextExtent(str);

   // Add the avg width to prevent clipping
   sz.cx += tm.tmAveCharWidth;

   if (sz.cx > dx)
      dx = sz.cx;
}
// Select the old font back into the DC
pDC->SelectObject(pOldFont);
m_pComboBox->ReleaseDC(pDC);

// Set the horizontal extent so every character of all strings can  
// be scrolled to.
m_pComboBox->SetHorizontalExtent(dx);

요구 사항

헤더: afxwin.h

참고 항목

참조

CComboBox 클래스

계층 구조 차트

CComboBox::GetHorizontalExtent

CB_SETHORIZONTALEXTENT