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;
}
}
'프로그래밍 > MFC' 카테고리의 다른 글
error LNK2001: unresolved external symbol __imp__TransparentBlt@44 (0) | 2011.04.14 |
---|---|
GetPrivateProfileString (0) | 2011.04.11 |
콤보박스 다운리스트 높이 지정하기 (0) | 2011.04.07 |
MFC 콤보박스 함수 설명 (0) | 2011.04.07 |
MFC - debug 창에 디버깅값 출력하기 (0) | 2011.03.25 |