CListCtrl的问题,我想改变某行字体的颜色,前面的CheckBox怎么办?

hellopower 2006-09-29 04:41:58
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;表示这个小格子完全由自己来画,问题是能只画格子中的字符串部分么,谢谢
...全文
328 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
payou444 2007-01-11
  • 打赏
  • 举报
回复
大概因为你的listCtrl选中了自绘属性,所以不会显示出checkbox.
将listCtrl的自绘属性去掉然后用
DWORD styles =LVS_EX_CHECKBOXES;
m_lctrl.SetExtendedStyle(styles);

即可
wxshzf 2006-11-19
  • 打赏
  • 举报
回复
帮顶接分
hellopower 2006-09-29
  • 打赏
  • 举报
回复
没有人做过改变ListView中的字体颜色么?

15,976

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧