[MFC]CListView列表视图

本文详细介绍了CListView在MFC中的应用,包括列表视图的四种样式、初始化样式设置、创建步骤、操作方法以及如何修改样式。重点讨论了在不同模式下,如大图标、小图标、列表和报表模式的特性,以及如何添加和编辑项目,调整列宽,以及在程序运行中动态改变列表视图的样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 列表视图简介:

    1) 最常见的列表视图案例就是Windows的资源管理器的右侧视图,就是使用列表视图来展示当前路径下的文件集合的;

    2) 列表视图有两大元素,一是文本,而是图形,和树形视图一样,但是这两种元素的展示形式会根据列表视图的样式发生改变;

    3) Windows支持的4中列表视图的样式:

         i. 小图标:


         ii. 大图标:


         iii. 列表:


         iv. 报表(详细):

 

    4) 在小图标、大图标和列表三种样式中,每个图标文字组合都是一个项目,而在报表模式中除了顶上的标题栏之外,其它每一行都是一个项目,其中最左列是主项目,右侧的列是主项目的子项目,像这里Lecture1.ppt就是主项目,Size的4372480和Last Modified的9/18/15(8:04a)这两项是Lecture1.ppt的子项目,这回在编程中具体体现出来;

    5) 列表视图类是CListView,它继承自列表控件CListCtrl,并派生出了大部分功能,在列表视图中要使用列表的有关功能就必须调用CListView的GetListCtrl获得视图内部的列表空间的引用:CListCtrl& CListView::GetListCtrl() const;


2. 列表视图的初始样式:

    1) 初始化列表视图时必须要覆盖CListView::PreCreateWindow函数,并设置cs.style来给出列表视图的默认样式;

    2) 下表给出里列表视图的通用样式,其它没给出的一些样式是应用在Explorer浏览器中,这里就先不做说明:

         i. 所有样式的前缀都是LVS_,即List View Style的缩写,即列表视图样式;

         ii. 首先是四种显示模式:

LVS_ICON:大图标模式

LVS_SMLLICON:小图标模式

LVS_LIST&

非常好用的CListCtrl加强版。 从CListCtrl继承,完全兼容CListCtrl. 它有以下特性: • The background of the sorted column can be displayed in a different color (like the detailed view of Windows XP Explorer). • The header of the sorted column can display an arrow that indicates the sort direction (like the detailed view of Windows XP Explorer). • You can give the user the opportunity to hide or redisplay selected columns by just clicking on the header control with the right mouse button (see picture below). • You can hide or redisplay a selected column entirely. • In contrast to the original list view control, the first column can have the LVCFMT_CENTER or LVCFMT_RIGHT style, too. For this feature, the list view control must have the LVS_OWNERDRAWFIXED style. • The label attributes state icon, small icon, and selection can always be shown in the leftmost column, independent of the order of the columns. For this feature, the listview control must have the LVS_OWNERDRAWFIXED style. • You can supply tooltips not only for the whole item, but also for the small icon, the state icon, and each subitem label. • The extended styles LVS_EX_CHECKBOXES, LVS_EX_ONECLICKACTIVATE, LVS_EX_SUBITEMIMAGES, LVS_EX_TWOCLICKACTIVATE, and LVS_EX_UNDERLINEHOT will be supported even if the list view control has the LVS_OWNERDRAWFIXED style. • If the LVS_EX_CHECKBOXES style has been applied and a selected item will be checked/unchecked, all other selected items will be checked/unchecked, too. • If the LVS_EX_LABELTIP style has been applied, not only the partially hidden text of the item label will be unfolded but also the partially hidden text of each subitem label. Note: The LVS_EX_LABELTIP style will be supported under all operating systems. • Tooltips and expanded labels can be displayed simultaneously. • The current state of the list view control (column widths, column order, hidden columns, and sort column and direction) can be saved and restored.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值