- MFC 教程
- MFC - 首页
- MFC - 概述
- MFC - 环境设置
- MFC - VC++ 项目
- MFC - 入门
- MFC - Windows 基础
- MFC - 对话框
- MFC - Windows 资源
- MFC - 属性表
- MFC - Windows 布局
- MFC - 控件管理
- MFC - Windows 控件
- MFC - 消息与事件
- MFC - ActiveX 控件
- MFC - 文件系统
- MFC - 标准 I/O
- MFC - 文档视图
- MFC - 字符串
- MFC - C数组
- MFC - 链表
- MFC - 数据库类
- MFC - 序列化
- MFC - 多线程
- MFC - 互联网编程
- MFC - GDI
- MFC - 库
- MFC 有用资源
- MFC - 快速指南
- MFC - 有用资源
- MFC - 讨论
MFC - 列表控件
封装了列表视图控件的功能,该控件显示项目的集合,每个项目由一个图标(来自图像列表)和一个标签组成。它由CListCtrl类表示。列表控件包含使用四种视图之一来显示项目列表。
- 图标
- 小图标
- 列表
- 报表
让我们通过创建一个新的基于 MFC 对话框的应用程序来了解一个简单的示例。
步骤 1 - 删除 TODO 行并拖动一个列表控件。
步骤 2 - 在“属性”窗口中,您将在“视图”下拉列表中看到不同的选项。
步骤 3 - 从“视图”字段中选择“报表”。
步骤 4 - 为列表控件添加控制变量 m_listCtrl。
步骤 5 - 在 OnInitDialog() 中初始化列表控件。
BOOL CMFCListControlDlg::OnInitDialog() {
CDialogEx::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// Ask Mfc to create/insert a column
m_listCtrl.InsertColumn(
0, // Rank/order of item
L"ID", // Caption for this header
LVCFMT_LEFT, // Relative position of items under header
100); // Width of items under header
m_listCtrl.InsertColumn(1, L"Name", LVCFMT_CENTER, 80);
m_listCtrl.InsertColumn(2, L"Age", LVCFMT_LEFT, 100);
m_listCtrl.InsertColumn(3, L"Address", LVCFMT_LEFT, 80);
int nItem;
nItem = m_listCtrl.InsertItem(0, L"1");
m_listCtrl.SetItemText(nItem, 1, L"Mark");
m_listCtrl.SetItemText(nItem, 2, L"45");
m_listCtrl.SetItemText(nItem, 3, L"Address 1");
nItem = m_listCtrl.InsertItem(0, L"2");
m_listCtrl.SetItemText(nItem, 1, L"Allan");
m_listCtrl.SetItemText(nItem, 2, L"29");
m_listCtrl.SetItemText(nItem, 3, L"Address 2");
nItem = m_listCtrl.InsertItem(0, L"3");
m_listCtrl.SetItemText(nItem, 1, L"Ajay");
m_listCtrl.SetItemText(nItem, 2, L"37");
m_listCtrl.SetItemText(nItem, 3, L"Address 3");
return TRUE; // return TRUE unless you set the focus to a control
}
步骤 6 - 编译并执行上述代码后,您将看到以下输出。
mfc_windows_controls.htm
广告