那一位高手对CListCtrl比较熟悉呀?小弟我先谢过了

newsb 2001-08-22 10:05:55
1:如何才能在对话框中的CListCtrl(report型)中将column的颜色改变?

2:一般来说,我在CListCtrl选中一个Item,它只有第一列背景色改变,我想
在我点击某一个Item的时候,整个Item的背景色都改变,如何实现?

3:还有就是在CListCtrl(icon型),我如何才能将图标当作其中的一项加入进去??

能说得稍微详细点吗?我一定给分的,谢谢
...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
newsb 2001-08-22
  • 打赏
  • 举报
回复
非常感谢,你的这篇文章是不是有个出处,如果能告诉小弟我
就更感激不尽了
prog_st 2001-08-22
  • 打赏
  • 举报
回复
1.
Change the background color of individual columns

--------------------------------------------------------------------------------
To set the background color of a column, the list view control has to be owner drawn. In an owner drawn control, each row is drawn by the application program rather than by the control. So when drawing a row, the background color can be set to our choice within the rectangle occupied by a particular column. To implement an owner drawn control see the topic 'Selection highlighting of entire row'.


The code segment below illustrates how to set yellow as the background color for alternate columns. The code shown is part of the DrawItem() function. The first segment draws the background color just before drawing the state icon. The second segment draws the background color within the loop that draws the labels for the remaining columns.

// Set clip region
rcCol.right = rcCol.left + GetColumnWidth(0);
CRgn rgn;
rgn.CreateRectRgnIndirect(&rcCol);
pDC->SelectClipRgn(&rgn);
rgn.DeleteObject();

// Draw column background
if( !bHighlight )
pDC->FillRect(rcCol, &CBrush(RGB(255,255,0)));

// Draw state icon
if (lvi.state & LVIS_STATEIMAGEMASK)

:
:
:
:

for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++)
{
rcCol.left = rcCol.right;
rcCol.right += lvc.cx;

// Draw column background
if( !bHighlight || ( bHighlight && m_nHighlight == HIGHLIGHT_NORMAL ) )
if( (nColumn+1) % 2 )
pDC->FillRect(rcCol, &CBrush(RGB(255,255,0)));

2.
m_listctrl.SetExtendedStyle(m_listctrl.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
3.
Example

// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
// The new image list of the list view control.
extern CImageList* pmyImageList;//初始化中创建ICON列表

/////////////////////////////


pmyListCtrl->SetImageList(pmyImageList, LVSIL_NORMAL);
ASSERT(pmyListCtrl->GetImageList(LVSIL_NORMAL) == pmyImageList);

//分别确定每个Item对应的ICON列表中的index

lizer 2001-08-22
  • 打赏
  • 举报
回复
搜索 "列表控件" 应该可以找到答案的

16,473

社区成员

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

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

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