void CUserListDlg::OnSize( UINT nType, int cx, int cy ) { CDialog::OnSize( nType, cx, cy ); CListBox* userList = (CListBox*)GetDlgItem( IDC_USERLIST ); CButton* newButton = (CButton*)GetDlgItem( IDC_NEWUSERBUTTON ); CButton* deleteButton = (CButton*)GetDlgItem( IDC_DELETEUSERBUTTON ); if ( userList && newButton && deleteButton ) { CRect client; GetClientRect( client ); CRect button; newButton->CButton::GetWindowRect( button ); userList->MoveWindow( 0, 0, client.Width(), client.Height()-button.Height() ); newButton->MoveWindow( 0, client.Height()-button.Height(), client.Width()/2, button.Height() ); deleteButton->MoveWindow( client.Width()/2, client.Height()-button.Height(), client.Width()/2, button.Height() ); } }
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; }