Share via


CListBox::SetHorizontalExtent

목록 상자를 가로로 스크롤할 수 픽셀 단위로 너비를 설정 합니다.

void SetHorizontalExtent( 
   int cxExtent  
);

매개 변수

  • cxExtent
    목록 상자를 가로로 스크롤할 수 픽셀 수를 지정 합니다.

설명

목록 상자의 크기가이 값 보다 작으면 항목 목록 상자에 가로 스크롤 막대가 가로로 스크롤됩니다. 목록 상자 같은 대규모 또는이 값 보다 큰 경우 가로 스크롤 막대가 숨겨집니다.

호출에 응답 하려면 SetHorizontalExtent, 목록 상자에 정의 되어 있어야는 WS_HSCROLL 스타일입니다.

이 멤버 함수는 다중 열 목록 상자에 대 한 유용 하지 않습니다. 다중 열 목록 상자에 대 한 호출을 SetColumnWidth 멤버 함수입니다.

예제

// Find the longest string in the list box.
CString    str;
CSize      sz;
int        dx = 0;
TEXTMETRIC tm;
CDC*       pDC = m_myListBox.GetDC();
CFont*     pFont = m_myListBox.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_myListBox.GetCount(); i++)
{
   m_myListBox.GetText(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_myListBox.ReleaseDC(pDC);

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

요구 사항

헤더: afxwin.h

참고 항목

참조

CListBox 클래스

계층 구조 차트

CListBox::GetHorizontalExtent

CListBox::SetColumnWidth

LB_SETHORIZONTALEXTENT