CListCtrl的问题,我想改变某行字体的颜色,前面的CheckBox怎么办?
CListCtrl的问题,我想改变某行字体的颜色,已经通过重载CListCtrl的NM_CUSTOMDRAW消息的响应函数来实现了,我的ListView是每行前面带CheckBox的那种类型,即
dwStyle |= LVS_EX_CHECKBOXES;//item前生成checkbox控件
m_PlayListCtrl.SetExtendedStyle( dwStyle);
我在重载的函数中自己用DrawText画出了要显示的字符串,那前面的CheckBox框怎么办阿,现在是空的,即没有画出CheckBox,我想让CListView自己来管理着一块,怎么办谢谢,下面是函数代码:
void CLeMusicPlayListMFCDlg::OnNMCustomdrawListPlaylist(NMHDR *pNMHDR, LRESULT *pResult)
{
//draw each item.set txt color,bkcolor....
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 (pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
{
// This is the prepaint stage for a subitem. Here's where we set the
// item's text and background colors. Our return value will tell
// Windows to draw the subitem itself, but it will use the new colors
// we set here.
int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
int nSubItem = pLVCD->iSubItem;
COLORREF crText = COLORREF(RGB(0,255,0));
COLORREF crBkgnd = COLORREF(RGB(255,255,255));
COLORREF crTextCommon = COLORREF(RGB(0,0,0));
COLORREF crBkgndCommon = COLORREF(RGB(255,255,255));
CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
CRect rect;
rect = pLVCD->nmcd.rc;
if (m_PlayListCtrl.GetItemState(nItem, LVIS_SELECTED))
DrawText(nItem, nSubItem, pDC, crTextCommon, crBkgndCommon , rect);
else
DrawText(nItem, nSubItem, pDC, crText, crBkgnd, rect);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
}
其中*pResult = CDRF_SKIPDEFAULT;表示这个小格子完全由自己来画,问题是能只画格子中的字符串部分么,谢谢