- 公开视频 -> 链接点击跳转公开课程
- 博客首页 -> 链接点击跳转博客主页
目录
列表视图(ListView)
控件类型
详细信息视图(Report View):数据以列的形式显示,每个项目可以有多个属性或字段。
图标视图(Icon View):数据以图标的形式显示,通常用于文件和文件夹等对象。
初始化控件环境
- 包含公共控件的头文件
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
- 调用
InitCommonControlsEx
函数
示例代码
case WM_INITDIALOG:
{
// 初始环境
INITCOMMONCONTROLSEX initComm = { 0 };
initComm.dwSize = sizeof(INITCOMMONCONTROLSEX);
initComm.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&initComm);
// 初始控件
HWND hListView = GetDlgItem(hwnd, IDC_LIST5);
ListView_SetExtendedListViewStyle(hListView, ListView_GetExtendedListViewStyle(hListView) | LVS_EX_FULLROWSELECT);
LVCOLUMN lvc = { 0 };
lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
lvc.pszText = (LPWSTR)TEXT("进程标识");
lvc.cx = 150;
lvc.iSubItem = 0;
ListView_InsertColumn(hListView, 0, &lvc);
lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
lvc.pszText = (LPWSTR)TEXT("进程文件");
lvc.cx = 150;
lvc.iSubItem = 1;
ListView_InsertColumn(hListView, 1, &lvc);
LVITEM lvi = { 0 };
lvi.mask = LVIF_TEXT;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = (LPWSTR)TEXT("1024");
ListView_InsertItem(hListView, &lvi);
ListView_SetItemText(hListView, 0, 1, (LPWSTR)TEXT("C:\\Windows\\System32\\notepad.exe"));
lvi.mask = LVIF_TEXT;
lvi.iItem = 1;
lvi.iSubItem = 0;
lvi.pszText = (LPWSTR)TEXT("2048");
ListView_InsertItem(hListView, &lvi);
ListView_SetItemText(hListView, 1, 1, (LPWSTR)TEXT("C:\\Windows\\System32\\calc.exe"));
return TRUE;
}
case WM_NOTIFY:
{
NMHDR* Info = (NMHDR*)lParam;
switch (Info->idFrom)
{
case IDC_LIST5:
{
if (Info->code == NM_CLICK)
{
INT nIndex = ListView_GetNextItem(Info->hwndFrom, -1, LVNI_SELECTED);
TCHAR szBuffer[0xFF] = { 0 };
ListView_GetItemText(Info->hwndFrom, nIndex, 0, szBuffer, 0xFF);
OutputDebugString(szBuffer);
}
}
}
return TRUE;
}