怎样改变listBox里字体的颜色?请指教,高分诱惑!
例如:if(flag) to be Red;
      if(!flag) to be Green;

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc.asp?id=400
      

  2.   

    HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    // TODO: Change any attributes of the DC here
    if(nCtlColor == CTLCOLOR_LISTBOX)
    {
        if(flag)
                    pDC->SetTextColor(RGB(255,0,0));
                 else
                    pDC->SetTextColor(RGB(0,255,0));
    } // TODO: Return a different brush if the default is not desired
    return hbr;
    }
      

  3.   

    继承CListBox类,重载DrawItem()函数,如下:void CMyListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your code to draw the specified item   ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX);
       LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
       ASSERT(lpszText != NULL); CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);   // Save these value to restore them when done drawing.
       COLORREF crOldTextColor = pDC->GetTextColor();
       COLORREF crOldBkColor = pDC->GetBkColor();   if( ! m_bValuable[lpDrawItemStruct->itemID] )
       {
      pDC->SetTextColor(RGB(128, 128, 128));
      pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
      pDC->FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
       } // If this item is selected, set the background color 
    // and the text color to appropriate values. Also, erase
    // rect by filling it with the background color.
    if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
    (lpDrawItemStruct->itemState & ODS_SELECTED))
    {
    if( m_bValuable[lpDrawItemStruct->itemID] )
    {
    pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
    pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
    pDC->FillSolidRect(&lpDrawItemStruct->rcItem, 
             ::GetSysColor(COLOR_HIGHLIGHT));
    }
    else
    {
    pDC->SetTextColor(RGB(200, 100, 200));
    pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
    pDC->FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
    }
    }
    else
    pDC->FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);   // Draw the text.
       pDC->DrawText(
          lpszText,
          strlen(lpszText),
          &lpDrawItemStruct->rcItem,
          DT_LEFT|DT_SINGLELINE|DT_VCENTER);   // Reset the background color and the text color back to their
       // original values.
       pDC->SetTextColor(crOldTextColor);
       pDC->SetBkColor(crOldBkColor);//   dc.Detach();
    }
      

  4.   

    happyparrot(快乐鹦鹉) : [email protected]
    zhucde(【風間苍月】)(MVP)::是动态过程中的 ,不是静止的,
                                 在滚动过程中,改变某一行的背景色或字体颜色。
      

  5.   

    happyparrot(快乐鹦鹉) ,你也是啊!:)
      

  6.   

    是动态过程中的 ,不是静止的,在滚动过程中,
    if(flag) to be Red;
    if(!flag) to be Green;改变某一行的背景色或字体颜色 
    up
    up
    up
      

  7.   

    DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 应该符合你的要求,自己绘制每个item呀!