/************************************************************************************** Function Name : SetHorizExtentListBox Input(s) : CListBox& omListBox Output : void Functionality : Sets the Listbox scroll to an extent so as to view the longest string that is inserted. Member of : CExploreMsgSg Author(s) : Robin G.K. Date Created : 27.10.2015 Requirement ID : RS_FLX_08_09_10 ***************************************************************************************/ void CExploreMsgSg::SetHorizExtentListBox(CListBox& omListBox) { // Set horizontal extent of the list // box to max string availaable // so that user can scroll CSize sz; CString omStrText; CDC* pDC = omListBox.GetDC(); if ( pDC != nullptr) { int nDx = 0; for (int nCount = 0; nCount < omListBox.GetCount(); nCount++) { omListBox.GetText( nCount, omStrText ); // remove space omStrText.TrimRight(); sz = pDC->GetTextExtent(omStrText); if (sz.cx > nDx) { nDx = sz.cx; } } omListBox.ReleaseDC(pDC); // Set the horizontal extent so every character of all // strings can be scrolled to. omListBox.SetHorizontalExtent(nDx); } }
CListBox* CPlayerListCtrl::ShowInPlaceListBox(int nItem, int nCol, CAtlList<CString>& lstItems, int nSel) { CRect rect; if (!PrepareInPlaceControl(nItem, nCol, rect)) { return nullptr; } DWORD dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL/*|WS_HSCROLL*/ | LBS_NOTIFY; CListBox* pListBox = DEBUG_NEW CInPlaceListBox(nItem, nCol, lstItems, nSel); pListBox->Create(dwStyle, rect, this, IDC_LIST1); CRect ir; GetItemRect(m_nItemClicked, &ir, LVIR_BOUNDS); pListBox->SetItemHeight(-1, ir.Height()); CDC* pDC = pListBox->GetDC(); CFont* pWndFont = GetFont(); pDC->SelectObject(pWndFont); int width = GetColumnWidth(nCol); POSITION pos = lstItems.GetHeadPosition(); while (pos) { int w = pDC->GetTextExtent(lstItems.GetNext(pos)).cx + 16; if (width < w) { width = w; } } ReleaseDC(pDC); CRect r; pListBox->GetWindowRect(r); ScreenToClient(r); r.top = ir.bottom; r.bottom = r.top + pListBox->GetItemHeight(0) * (pListBox->GetCount() + 1); r.right = r.left + width; pListBox->MoveWindow(r); m_fInPlaceDirty = false; return pListBox; }