请问如何在列表控件中画直线?

mefish 2001-09-11 08:13:19
就好像Windows NT下的性能监视器的不同计数器的画线颜色在列表中有显示那样
...全文
155 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mefish 2001-09-13
  • 打赏
  • 举报
回复
本人经过一番苦思冥想,找到了一个“瞒天过海”的办法,就是不用位图,而是用彩色文字,文字是制表符"───",人们会以为这是一条横线。方法如下,供大家共享:
首先截获列表控件的“自画”消息,
BEGIN_MESSAGE_MAP(CSysMonitorClientView, CFormView)
ON_NOTIFY(NM_CUSTOMDRAW, IDC_PROCESS_LIST, OnCustomdrawList)
END_MESSAGE_MAP()
在头文件中定义函数
afx_msg ;
实现函数如下:
void OnCustomdrawList (NMHDR* pNMHDR, LRESULT* pResult)
{
//ysy:get the code fragment from
//ysy: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 )
{
// 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.

COLORREF crText;

if ( 0 == pLVCD->iSubItem)
crText=RGB(255,0,0); //换成自己的颜色
else
crText = RGB(0,0,0);

// Store the colors back in the NMLVCUSTOMDRAW struct.
pLVCD->clrText = crText;

// Tell Windows to paint the control itself.
*pResult = CDRF_DODEFAULT;
}
}

更多内容请访问http://www.codeproject.com/listctrl/lvcustomdraw.asp,不过是e问的哦
prog_st 2001-09-12
  • 打赏
  • 举报
回复
不过你的CImageList可得特殊创建
prog_st 2001-09-12
  • 打赏
  • 举报
回复
那有什么害怕的!创建CImageList,关联到CListCtrl
mefish 2001-09-12
  • 打赏
  • 举报
回复
我试试看吧,我对位图的操作还是很害怕的
prog_st 2001-09-12
  • 打赏
  • 举报
回复
创建位图,位图上画线,加载位图!
mefish 2001-09-12
  • 打赏
  • 举报
回复
我不是在为列表控件画格,而是列表项中画横线,请看http://go.163.com/lsye/question.jpg
谢谢!
ahphone 2001-09-11
  • 打赏
  • 举报
回复
可以参考
http://www.csdn.net/dev/visual%20c++/source%20code/ListView/grid_lines.shtml.htm
其他类似对可以见http://www.csdn.net/dev/visual%20c++/->source->ListView Control

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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