Beispiel #1
0
CComboBox* CPlayerListCtrl::ShowInPlaceComboBox(int nItem, int nCol, CAtlList<CString>& lstItems, int nSel, bool bShowDropDown)
{
    CRect rect;
    if (!PrepareInPlaceControl(nItem, nCol, rect)) {
        return nullptr;
    }

    DWORD dwStyle = /*WS_BORDER|*/WS_CHILD | WS_VISIBLE | WS_VSCROLL /*|WS_HSCROLL*/
                                  | CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL/*|CBS_NOINTEGRALHEIGHT*/;
    CComboBox* pComboBox = DEBUG_NEW CInPlaceComboBox(nItem, nCol, lstItems, nSel);
    pComboBox->Create(dwStyle, rect, this, IDC_COMBO1);

    CorrectComboListWidth(*pComboBox);

    int width = GetColumnWidth(nCol);
    if (pComboBox->GetDroppedWidth() < width) {
        pComboBox->SetDroppedWidth(width);
    }

    if (bShowDropDown) {
        pComboBox->ShowDropDown();
    }

    m_fInPlaceDirty = false;

    return pComboBox;
}
Beispiel #2
0
void CAutoComplete::DoCompletion(CWnd* pWnd, CString s,
								 const CStringArray& arMatches)
								 
{
	
	if (m_iType==ComboBox)
	{
		
		// 这种强制转换从技术上讲是不正确的,但它是一个标准的MFC诀窍.
		
		CComboBox* pComboBox = (CComboBox*)pWnd;
		
		// 更新下拉框以反映可能的匹配
		
		pComboBox->ResetContent();

		
		for (int i=0; i <arMatches.GetSize();i++)
			
			pComboBox->AddString(arMatches[i]);
		
		// 用户箭头光标,这样用户才能选择
		
		::SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)));
		
		// 显示下拉框
		
		pComboBox->ShowDropDown();
		
		pComboBox->SetWindowText(IgnoreCompletion(s) ? s : arMatches[0]);
		
		pComboBox->SetEditSel(s.GetLength(),-1);  //设置高亮
		
	} 
	else if (m_iType==Edit && !IgnoreCompletion(s)) 
	{
		
		// 这种强制转换从技术上讲是不正确的,但它是一个标准的MFC诀窍.
		
		CEdit* pEdit = (CEdit*)pWnd;
		
		pEdit->SetWindowText(arMatches[0]);
		
		pEdit->SetSel(s.GetLength(),-1);
		
	}

}
Beispiel #3
0
CComboBox* CMySuperGrid::ShowList(int nItem, int nCol, CStringList *lstItems)
{
	CString strFind = GetItemText(nItem, nCol);

	//basic code start
	CRect rect;
	int offset = 0;
	// Make sure that the item is visible
	if( !EnsureVisible(nItem, TRUE)) return NULL;
	GetSubItemRect(nItem, nCol, LVIR_BOUNDS, rect);
	// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect(rcClient);
	if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
	{
		CSize size;
		size.cx = offset + rect.left;
		size.cy = 0;
		Scroll(size);
		rect.left -= size.cx;
	}
	
	rect.left += offset;	
	rect.right = rect.left + GetColumnWidth(nCol);
	if(rect.right > rcClient.right) 
	   rect.right = rcClient.right;
	//basic code end

	rect.bottom += 10 * rect.Height();//dropdown area
	
	DWORD dwStyle =  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL|CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL;
	CComboBox *pList = new CComboInListView(nItem, nCol, lstItems);
	pList->Create(dwStyle, rect, this, IDC_COMBOBOXINLISTVIEW);
	pList->ModifyStyleEx(0,WS_EX_CLIENTEDGE);//can we tell at all
	pList->SetHorizontalExtent(CalcHorzExtent(pList, lstItems));
	pList->ShowDropDown();
	pList->SelectString(-1, strFind.GetBuffer(1));
	// The returned pointer should not be saved
	return pList;
}