void AutoSetComboBoxHeight(CComboBox& c) { int itemCount = c.GetCount() + 1; int itemHeight = c.GetItemHeight(0); int editAreaHeight = c.GetItemHeight(0); int targetHeight = editAreaHeight + (itemHeight * itemCount); RECT rc; c.GetWindowRect(&rc); c.GetParent().ScreenToClient(&rc); rc.bottom = rc.top + targetHeight; c.MoveWindow(&rc, FALSE); }
void CPlayerListCtrl::OnCbnDropdownCombo1() { CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO1); CRect ir; GetItemRect(m_nItemClicked, &ir, LVIR_BOUNDS); CRect r; pCombo->GetWindowRect(r); ScreenToClient(r); r.bottom = r.top + ir.Height() + pCombo->GetItemHeight(0) * 10; pCombo->MoveWindow(r); }