我在一个基于对话框的界面上放置了一个CListCtrl,并设置成report形式。想要动态改变CListCtrl中显示的字体,该如何实现呢?

解决方案 »

  1.   

    LOGFONT m_lf;
    CFont font;
    m_lf.lfWidth = m_CharWidth;
    m_lf.lfHeight = m_LineHeight;
    m_lf.lfCharSet = GB2312_CHARSET;
    m_lf.lfOutPrecision = 3;
    m_lf.lfClipPrecision = 2;
    m_lf.lfQuality = PROOF_QUALITY;
    m_lf.lfPitchAndFamily = 49;
    m_lf.lfEscapement = 0;
    m_lf.lfOrientation = 0;
    m_lf.lfUnderline = 0;
    m_lf.lfPitchAndFamily = DEFAULT_PITCH|FF_ROMAN;
    font.CreateFont(m_lf.lfHeight,
    m_lf.lfWidth,
    m_lf.lfEscapement,
    m_lf.lfOrientation,
    FW_NORMAL,
    FALSE,
    m_lf.lfUnderline,
             0,
    m_lf.lfCharSet,
    m_lf.lfOutPrecision,
    m_lf.lfClipPrecision,
    m_lf.lfQuality,
    m_lf.lfPitchAndFamily,
             "宋体");然后你的CListCtrl动态的选择就可以了,或在一定的条件下用什么样的字体,自已用SetFont()来选择就可以了
      

  2.   

    在这改变字体
    HBRUSH CLogToolDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
        if(pWnd->GetDlgCtrlID() == IDC_EDIT_LOG)
        {
            static HBRUSH hbrEdit = ::CreateSolidBrush(RGB(255, 255, 255));
            pDC->SetBkColor(RGB(255, 255, 255));
            pDC->SetTextColor(RGB(0, 0, 255));
            return hbrEdit;
        }
    // TODO: Return a different brush if the default is not desired
    return hbr;
    } //
      

  3.   

    .h 定义数据成员
    CFont m_font;
    .cpp
    m_font.CreatePointFont(2,"宋体");
    m_listctrl.SetFont(&m_font);