'Clist 글자색 변경'에 해당되는 글 1건

  1. 2011.05.09 CList 글자색 변경하기
프로그래밍/MFC2011. 5. 9. 09:28



1. 헤더파일에 afx_msg void OnCustomDrawList( NMHDR* pNMHDR, LRESULT* pResult ) 추가

2. cpp 파일에 ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST1, OnCustomDrawList)

3. void CDlg::OnCustomDrawList ( NMHDR* pNMHDR, LRESULT* pResult ) 구현

void CDlg::OnCustomDrawList ( NMHDR* pNMHDR, LRESULT* pResult )     // 리스트 데이터 글자색 변경
{
 //This code based on Michael Dunn's excellent article on
 //list control custom draw at http://www.codeproject.com/listctrl/lvcustomdraw.asp
 
 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
 
    // Take the default processing unless we set this to something else below.
    *pResult = CDRF_DODEFAULT;
 
    // First thing - check the draw stage. If it's the control's prepaint
    // stage, then tell Windows we want messages for every item.
 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
 {
        *pResult = CDRF_NOTIFYITEMDRAW;
 }
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
 {
        // This is the notification message for an item.  We'll request
        // notifications before each subitem's prepaint stage.
  
        *pResult = CDRF_NOTIFYSUBITEMDRAW;
 }
    else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
 {
  
  COLORREF clrNewTextColor, clrNewBkColor;
       
  int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec ); //row
  
  CString strTemp = m_list1.GetItemText(nItem,pLVCD->iSubItem);
  float rt_06, rate;
  
  
  switch(pLVCD->iSubItem)
  {
  case 0:
   break;
  case 1:
   break;
  case 2:
   rt_06 = atof(strTemp);
   if(rt_06 > 0)
    clrNewTextColor = RGB(255, 0, 0);
   else if(rt_06 <0)
    clrNewTextColor = RGB(0, 0, 255);
   else
    clrNewTextColor = RGB(0, 0, 0);
   pLVCD->clrText = clrNewTextColor;
   break;
  case 3:
   rate = atof(strTemp);
   if(rate > 0)
    clrNewTextColor = RGB(255, 0, 0);
   else if(rate <0)
    clrNewTextColor = RGB(0, 0, 255);
   else
    clrNewTextColor = RGB(0, 0, 0);
   
   pLVCD->clrText = clrNewTextColor;
   break;
  case 4:
   clrNewTextColor = RGB(0, 0, 0);
   pLVCD->clrText = clrNewTextColor;
   break;

  }
        *pResult = CDRF_DODEFAULT;       
 }
}

Posted by 마블(이환문)