Beispiel #1
0
void CTTComboBox::AlignListBoxWithCombo()
{
	if (m_cbi.hwndList == NULL ||
		!::IsWindow(m_cbi.hwndList))
		return;

	CListBox* pList = (CListBox*)CWnd::FromHandle(m_cbi.hwndList);
	CRect l_rcCombo;
	GetClientRect(&l_rcCombo);
	CRect l_rcList;
	pList->GetClientRect(&l_rcList);
	int dropWidth = GetDroppedWidth();
	int listWidth = l_rcList.Width();
	int xOffset = 0;
	switch (m_alignStyle)
	{
	case 0:
		xOffset = 0;
		break;
	case 1:
		xOffset = dropWidth - l_rcCombo.Width();
		break;
	case 2:
		xOffset = (dropWidth - l_rcCombo.Width()) / 2;
		break;
	default:
		xOffset = 0;
		break;
	}
	pList->ClientToScreen(&l_rcList);
	pList->SetWindowPos(NULL, l_rcList.left - xOffset, l_rcList.top, 0, 0, SWP_NOSIZE);
}
Beispiel #2
0
void CColorCombo::InitDialog(HWND hWndCtrl, bool bDefaultColors, bool bAllowOffOption)
{
	if (!hWndCtrl)
		return;

	SubclassWindow(hWndCtrl);

	AddComboToList();

	long lWidth = GetDroppedWidth();
	long lRet = SetDroppedWidth(dtoi(2.75 * lWidth));

	// Stuff the combobox with colors
	
	// Add a place holder for the Custom option (the color picker)
	int nItem = AddString("");
	SetItemData(nItem, CLR_NONE);

	if (bAllowOffOption)
	{
		nItem = AddString("");
		SetItemData(nItem, CLR_DEFAULT);
	}

	if (bDefaultColors)
	{
		for (int i = 0; i < NDEFAULTCOLORS; i++)
		{
			nItem = AddString("");
			SetItemData(nItem, CColorCombo::m_DefaultColors[i].Color);
		}
	}
}
Beispiel #3
0
BOOL CInPlaceList::OnDropdown()
{
    // TODO: Add your control notification handler code here

    SetCursor(LoadCursor(NULL, IDC_ARROW));

    int dx = 0;
    CSize sz(0,0);
    TEXTMETRIC tm;
    CString sLBText;
    CDC* pDC = GetDC();
    CFont* pFont = GetFont();
    // Select the listbox font, save the old font
    CFont* pOldFont = pDC->SelectObject(pFont);
    // Get the text metrics for avg char width
    pDC->GetTextMetrics(&tm);

    const int nCount = GetCount();
    for(int i = 0; i < nCount; ++i)
    {
        GetLBText(i, sLBText);
        sz = pDC->GetTextExtent(sLBText);
        // Add the avg width to prevent clipping
        sz.cx += tm.tmAveCharWidth;
        if(sz.cx > dx)
            dx = sz.cx;
    }

    // Select the old font back into the DC
    pDC->SelectObject(pOldFont);
    ReleaseDC(pDC);

    // Adjust the width for the vertical scroll bar and the left and right border.
    dx += ::GetSystemMetrics(SM_CXVSCROLL) + 2 * ::GetSystemMetrics(SM_CXEDGE);
    if(GetDroppedWidth() < dx)
        SetDroppedWidth(dx);

    return Default() != 0;
}