当前位置: 首页>>代码示例>>C++>>正文


C++ CGridListCtrlEx::GetCellFont方法代码示例

本文整理汇总了C++中CGridListCtrlEx::GetCellFont方法的典型用法代码示例。如果您正苦于以下问题:C++ CGridListCtrlEx::GetCellFont方法的具体用法?C++ CGridListCtrlEx::GetCellFont怎么用?C++ CGridListCtrlEx::GetCellFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGridListCtrlEx的用法示例。


在下文中一共展示了CGridListCtrlEx::GetCellFont方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetTextRect

//------------------------------------------------------------------------
//! Returns dimensions of the cell text clicked
//!
//! @param owner The list control being clicked
//! @param nRow The index of the row
//! @param nCol The index of the column
//! @param cellText The contents of the cell clicked
//! @return The dimensions of the cell text
//------------------------------------------------------------------------
CRect CGridColumnTraitHyperLink::GetTextRect(CGridListCtrlEx& owner, int nRow, int nCol, const CString& cellText)
{
	CRect rect;
	ASSERT(nRow != -1);
	CDC* pDC = owner.GetDC();
	CFont* pOldFont = pDC->SelectObject(owner.GetCellFont());
	CSize size = pDC->GetTextExtent(cellText);
	pDC->SelectObject(pOldFont);
	owner.ReleaseDC(pDC);

	owner.GetCellRect(nRow, nCol, LVIR_LABEL, rect);

	HDITEM hditem = { 0 };
	hditem.mask = HDI_FORMAT;
	owner.GetHeaderCtrl()->GetItem(nCol, &hditem);

	// First item (Label) doesn't have a margin (Subitems does)
	if (nCol != 0 && !(hditem.fmt & HDF_CENTER))
	{
		if (hditem.fmt & HDF_RIGHT)
			rect.OffsetRect(-7, 0);
		else
			rect.OffsetRect(4, 0);
	}

	if (hditem.fmt & HDF_CENTER)
		rect.DeflateRect((rect.Width() - size.cx) / 2, 0);
	else if (hditem.fmt & HDF_RIGHT)
		rect.left = rect.right - size.cx;
	else
		rect.right = rect.left + size.cx;
	return rect;
}
开发者ID:copyspace,项目名称:cgridlistctrlex,代码行数:42,代码来源:CGridColumnTraitHyperLink.cpp

示例2: GetCellFontHeight

//------------------------------------------------------------------------
//! Calculates the proper row-height according to font, which a cell value
//! editor should fit in.
//!
//! @param owner The list control for the inplace cell value editor
//! @return Height in pixels of the row.
//------------------------------------------------------------------------
int CGridColumnTraitText::GetCellFontHeight(CGridListCtrlEx& owner)
{
	const CString testText = _T("yjpÍÁ");

	CRect rcRequired = CRect(0, 0, 0, 0);

	CClientDC dc(&owner);
	dc.SelectObject(owner.GetCellFont());
	dc.DrawText(testText, &rcRequired, DT_CALCRECT | DT_SINGLELINE);

	return rcRequired.Height();
}
开发者ID:matt-wu,项目名称:Moure,代码行数:19,代码来源:CGridColumnTraitText.cpp

示例3: OnCustomDraw

//------------------------------------------------------------------------
//! Overrides the custom draw handler, to allow custom coloring of rows.
//!		- Focus rectangle display
//!		- Use font size to increase row-height, but keep cell font-size
//!		- Alternate row coloring
//!
//! @param owner The list control drawing
//! @param pLVCD Pointer to NMLVCUSTOMDRAW structure
//! @param pResult Modification to the drawing stage (CDRF_NEWFONT, etc.)
//------------------------------------------------------------------------
void CGridRowTraitText::OnCustomDraw(CGridListCtrlEx& owner, NMLVCUSTOMDRAW* pLVCD, LRESULT* pResult)
{
    int nRow = (int)pLVCD->nmcd.dwItemSpec;

    switch (pLVCD->nmcd.dwDrawStage)
    {
    case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
    {
        // Remove the selection color for the focus cell, to make it easier to see focus
        if (m_InvertCellSelection)
        {
            int nCol = pLVCD->iSubItem;
            if (pLVCD->nmcd.uItemState & CDIS_SELECTED)
            {
                if (owner.GetFocusCell()==nCol && owner.GetFocusRow()==nRow)
                {
                    pLVCD->nmcd.uItemState &= ~CDIS_SELECTED;
                }
            }
        }

        // Bug in Vista causes the cell color from previous cell to be used in the next
        // even if having reverted the cell coloring in subitem-post-paint
        if (pLVCD->clrText <= RGB(255,255,255) || pLVCD->clrTextBk <= RGB(255,255,255))
        {
            pLVCD->clrText = CLR_DEFAULT;
            pLVCD->clrTextBk = CLR_DEFAULT;

            if (UpdateTextColor(nRow, pLVCD->clrText))
                *pResult |= CDRF_NEWFONT;

            if (UpdateBackColor(nRow, pLVCD->clrTextBk))
                *pResult |= CDRF_NEWFONT;

            if (owner.OnDisplayRowColor(nRow, pLVCD->clrText, pLVCD->clrTextBk))
                *pResult |= CDRF_NEWFONT;
        }
    }
    break;

    // Before painting a row
    case CDDS_ITEMPREPAINT:
    {
        if (UpdateTextColor(nRow, pLVCD->clrText))
            *pResult |= CDRF_NEWFONT;

        if (UpdateBackColor(nRow, pLVCD->clrTextBk))
            *pResult |= CDRF_NEWFONT;

        if (owner.OnDisplayRowColor(nRow, pLVCD->clrText, pLVCD->clrTextBk))
            *pResult |= CDRF_NEWFONT;

        LOGFONT newFont = {0};
        if (owner.OnDisplayRowFont(nRow, newFont))
        {
            // New font provided
            CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
            CFont* pNewFont = new CFont;
            VERIFY( pNewFont->CreateFontIndirect(&newFont) );
            m_pOldFont = pDC->SelectObject(pNewFont);
            m_FontAllocated = true;
            *pResult |= CDRF_NOTIFYPOSTPAINT;	// We need to restore the original font
            *pResult |= CDRF_NEWFONT;
        }
        else
        {
            if (owner.GetFont()!=owner.GetCellFont())
            {
                // Using special cell font because of SetMargin()
                CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
                m_pOldFont = pDC->SelectObject(owner.GetCellFont());
                *pResult |= CDRF_NOTIFYPOSTPAINT;	// We need to restore the original font
                *pResult |= CDRF_NEWFONT;
            }
        }

        if (pLVCD->nmcd.uItemState & CDIS_FOCUS)
        {
            if (owner.GetFocus() != &owner)
                break;

            // If drawing focus row, then remove focus state and request to draw it later
            //	- Row paint request can come twice, with and without focus flag
            //	- Only respond to the one with focus flag, else DrawFocusRect XOR will cause solid or blank focus-rectangle
            if (owner.GetFocusRow() == nRow)
            {
                if (owner.GetFocusCell() >= 0)
                {
                    // We want to draw a cell-focus-rectangle instead of row-focus-rectangle
                    pLVCD->nmcd.uItemState &= ~CDIS_FOCUS;
//.........这里部分代码省略.........
开发者ID:strogo,项目名称:cgridlistctrlex,代码行数:101,代码来源:CGridRowTraitText.cpp


注:本文中的CGridListCtrlEx::GetCellFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。