void CListBoxDiffMarks::substituteControl(CWnd *parent, int id) {
  DEFINEMETHODNAME;
  CListBox *oldCtrl = (CListBox*)parent->GetDlgItem(id);
  if(oldCtrl == NULL) {
    showError(_T("%s:Control with id=%d does not exist"), method, id);
    return;
  }
  CRect wr;
  oldCtrl->GetWindowRect(&wr);
  parent->ScreenToClient(&wr);
  DWORD style   = oldCtrl->GetStyle();
  const DWORD exStyle = oldCtrl->GetExStyle();
  style |= LBS_OWNERDRAWFIXED | WS_BORDER;
  style &= ~(LBS_SORT);

  CFont *font = oldCtrl->GetFont();
  if(font == NULL) {
    font = parent->GetFont();
  }
  const CompactIntArray tabOrder = getTabOrder(parent);
  oldCtrl->DestroyWindow();

  if(!Create(style, wr, parent, id)) {
    showError(_T("%s:Create failed"), method);
    return;
  }
  setTabOrder(parent, tabOrder);
  ModifyStyleEx(0, exStyle);
  SetFont(font);
  m_charSize.cx = m_charSize.cy = 0;
  setEqualSelected(::GetSysColor(COLOR_HIGHLIGHTTEXT),::GetSysColor(COLOR_HIGHLIGHT   ));
  setDiffSelected( ::GetSysColor(COLOR_HIGHLIGHT    ),::GetSysColor(COLOR_HIGHLIGHTTEXT));
}
예제 #2
0
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;
}