下面的代码可以实现,CListBox中显示的都是一种字体,
因为特殊需要,有些行字体需要变大,
如何设置不同行中字体不一样呢?
// testDlg.h : header file
CFont m_font; //设置CListBox中字体大小
void AddStr(CString str); //向列表框按行追加数据// testDlg.cpp : implementation file
BOOL CtestDlg::OnInitDialog()
{
//设置字体属性
m_font.CreateFont(18,0,0,0,FW_DONTCARE,FALSE,FALSE,0, 1,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, 
DEFAULT_PITCH|FF_SWISS,"宋体"); 

AddStr("设置字体属性");
AddStr("hello world");

UpdateData(FALSE);

//设置控件中字体大小
GetDlgItem(IDC_LIST1)->SetFont(&m_font,1); 

return TRUE; 
}//按行追加数据
void CtestDlgg::AddStr(CString str)
{
((CListBox*)this->GetDlgItem(IDC_LIST1))->AddString(str); 
}

解决方案 »

  1.   

    http://blog.csdn.net/VisualEleven/archive/2010/12/13/6072404.aspx
      

  2.   

    自画,drawtext前选一种字体,这样就可以很多种了
      

  3.   


    void CMyComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your code to draw the specified item
        ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
        CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
        CString rString;
        if (lpDrawItemStruct->itemID == -1)
            return;

    int nIndexDC = pDC->SaveDC();
    CRect rect(lpDrawItemStruct->rcItem);

        GetLBText(lpDrawItemStruct->itemID, rString );
      
    // set font information to DC
        CFont font;
        LOGFONT logfont;
        memset(&logfont, 0, sizeof(logfont));
        logfont.lfHeight  = CBFONT_FONTHEIGHT;
        logfont.lfWidth   = CBFONT_FONTWIDTH;
        logfont.lfWeight  = CBFONT_FONTWEIGHT;
        logfont.lfCharSet = DEFAULT_CHARSET;

        pDC->SelectObject(&font);
        strcpy(logfont.lfFaceName, (LPCTSTR)rString);
        font.CreateFontIndirect(&logfont);
        pDC->SelectObject(&font);

       // draw every row
        int nX = rect.left; // x pos for MRU separater lines
        rect.left += CBFONT_IMAGEWIDTH + 2;
        
         CBrush brush;
         pDC->SetBkMode(TRANSPARENT);
        if (lpDrawItemStruct->itemState & ODS_SELECTED)
        {
    brush.CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
    pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
        }
        else
            brush.CreateSolidBrush(pDC->GetBkColor());
        pDC->FillRect(rect, &brush);
        pDC->DrawText(rString, rect, DT_SINGLELINE | DT_VCENTER);
        // restore state of DC
        pDC->RestoreDC(nIndexDC);
        brush.DeleteObject();
    }void CMyComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
    {
    // TODO: Add your code to determine the size of specified item
         lpMeasureItemStruct->itemHeight = 20;//set row's height
    }
      

  4.   

    粘的我自己写的字体的combo box
    有地方不对 。
     。
     // draw every row    
        int nX = rect.left; // x pos for MRU separater lines
        //rect.left += CBFONT_IMAGEWIDTH + 2;
     。
     。