重载父窗口(比如Dialog)的WM_CTLCOLORLISTBOX消息。
hdcLB = (HDC) wParam;
hwndLB = (HWND) lParam; 
然后用SetTextColor(hdcLB, RGB(0,255,255));
此外还可以用SetBkMode,SetTextBkColor设置字体背景模式和背景色。返回值是一个hBrush,ListBox将用它填充窗口背景。

解决方案 »

  1.   

    我这里又一篇文档,忘了从哪里摘的,就是长了一些,你看看
    I wanted to have a ListBox with the ability to change the font style of each item from normal to bold (like in the Message Maps property page of the ClassWizard). 
    In order to do that, I extended the CListBox class by adding two public methods that let users set/get the font style of each item. 
    typedef enum {NORMAL = 0, BOLD, ITALIC} FONTSTYLE;
    class CFontStyleListBox : public CListBox
    {
    // Construction
    public:
    CFontStyleListBox();
    // (...)
    public:
    FONTSTYLE GetFontStyle(int nIndex);
    void SetFontStyle(int nIndex, FONTSTYLE fontStyle);
    }
    For the implementation, I overrided the DrawItem method. It is clear that the information about the font style must be kept individually for each item. The easiest way I found (not necessarily the best) was to keep this information in the data associated to each item. That means that the user should not invoke the SetItemData/GetItemData methods. 
    void CFontStyleListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your code to draw the specified item
    CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect rect;
    // Draw the colored rectangle portion
    rect.CopyRect(&lpDrawItemStruct->rcItem);
    pDC->SetBkMode(TRANSPARENT);
    if (lpDrawItemStruct->itemState & ODS_SELECTED)
    {
    pDC->FillSolidRect (rect, GetSysColor(COLOR_HIGHLIGHT));
    pDC->SetTextColor (GetSysColor(COLOR_HIGHLIGHTTEXT));
    }
    else
    {
    pDC->FillSolidRect (rect, GetSysColor (COLOR_WINDOW));
    pDC->SetTextColor (GetSysColor(COLOR_WINDOWTEXT));
    }
    if ((int)(lpDrawItemStruct->itemID) >= 0) // Valid ID
    {
    CString sText;
    int nIndex;
    CFont newFont;
    CFont *pOldFont;
    nIndex = lpDrawItemStruct->itemID;
    GetText(nIndex, sText);
    FONTSTYLE fontStyle = (FONTSTYLE)GetItemData(nIndex);
    // To avoid unnecessary processing
    if (fontStyle == NORMAL) {
    pDC->DrawText(sText, rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    return;
    }
    LOGFONT logFont;
    CFont *pFont = GetFont();
    pFont->GetLogFont(&logFont);
    switch (fontStyle) 
    {
    //case NORMAL: logFont.lfWeight = FW_NORMAL;
    // break;
    case BOLD: logFont.lfWeight = FW_BOLD;
    break;
    case ITALIC: logFont.lfItalic = TRUE;
    break;
    }
    newFont.CreatePointFontIndirect (&logFont);
    pOldFont = pDC->SelectObject (&newFont);
    pDC->DrawText(sText, rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
    pDC->SelectObject (pOldFont);
    newFont.DeleteObject ();

    }
    FONTSTYLE CFontStyleListBox::GetFontStyle(int nIndex)
    {
    return (FONTSTYLE) GetItemData(nIndex);
    }
    void CFontStyleListBox::SetFontStyle(int nIndex, FONTSTYLE fontStyle)
    {
    SetItemData (nIndex, (DWORD) fontStyle);
    Invalidate();
    }
    If you use this class with a dialog resource, you must select in the Style Properties Owner Draw: Fixed and Has Strings options.