사용자가 텍스트를 입력하고 나중에 불러 오기/사용을 위해 텍스트를 드롭 다운 목록에 삽입하는 "저장"버튼을 클릭 할 수있는 C++ MFC CComboBox (VS 2010)가 있습니다. 텍스트가 상자에 비해 너무 길 때 스크롤 막대가 필요하므로 리소스 파일에 WS_HSCROLL을 설정하고 m_Combo.SetHorizontalExtent (x)를 사용하면됩니다.수동으로 MFC CComboBox 수평 스크롤 막대를 사용하여 드롭 다운 높이를 설정하십시오.
내가 가진 문제는 가로 스크롤이있는 곳에 한 줄이 그려져 있고 세로 스크롤 막대가 한 항목으로 스크롤하는 것입니다. 나는 지난 몇 일
m_Combo.MoveWindow(&rctDropDown) //rctDropDown was first pulled out and modified
::SetWindowPos() //called after modifying values from ::GetWindowRect()
r.OffsetRect() //where r is from m_Combo.GetDroppedControlRect(&r)
아마도 더 시도했지만 아무것도 가로 스크롤 고려하지 않습니다 드롭 다운의 자동 크기 조정을 무시할 것 같다. 나는 MFC를 처음 사용하여 필사적 인 Google 검색 중에 온라인에서 제안 된 것을 발견했습니다.
요약하면 자동 높이를 무시하거나 연장하는 방법이 있습니까? 리소스 편집기에서 크기를 조정하는 방법을 알고 있지만 런타임 중에 코드에서 크기를 조정하려고하면 모든 것이 무시되는 것 같습니다. 여기에 오류 재현 테스트 프로젝트에서 내 함수입니다 : 수평 스크롤을 추가하고 삭제 된 목록 상자가 충분히 넓은 아닌 경우 스크롤 허용하는 대신
void CtestDlg::StoreClicked()
{
CString l;
m_Combo.GetWindowText(l);
m_Combo.InsertString(0, l);
m_Combo.SetCurSel(0);
UpdateList();
}
void CtestDlg::UpdateList()
{
// Find the longest string in the list box.
CString str;
CSize sz;
TEXTMETRIC tm;
CDC* pDC = m_Combo.GetDC();
CFont* pFont = m_Combo.GetFont();
int x = 0;
int y = 0;
// 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_Combo.GetCount(); i++)
{
m_Combo.GetLBText(i, str);
sz = pDC->GetTextExtent(str);
// Add the avg width to prevent clipping
sz.cx += tm.tmMaxCharWidth;
m_Combo.SetItemHeight(i, sz.cy);
if (sz.cx > x)
x = sz.cx;
y += sz.cy;
}
// Select the old font back into the DC
pDC->SelectObject(pOldFont);
m_Combo.ReleaseDC(pDC);
m_Combo.SetHorizontalExtent(x);
////////////////////////////////
//manually change height here?//
////////////////////////////////
}
안녕 mwilliams와
교체? – SevenWow
아니요, MFC의 한계라고 생각합니다. – mwilliams