ListView-列表视图元素

listView 列表视图元素

列表视图元素,每个项包含大图标和文本,支持分组显示.

步骤:

  1. XListView_Create()创建列表视图元素.

示例代码 - 简化代码

#pragma comment(lib, "XCGUI.lib")
#include "xcgui.h"
HWINDOW hWindow = NULL;
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI(TRUE); //初始化
hWindow = XWnd_Create(0, 0, 600, 400, L"炫彩界面库-窗口");//创建窗口
if (hWindow)
{
HELE hListView = XListView_Create(20, 40, 500, 300, hWindow);
XListView_SetItemTemplateXML(hListView, L"XML-template\\ListView_Item.xml");
int group1 = XListView_Group_AddItemText(hListView, L"group1",-1);
int group2 = XListView_Group_AddItemText(hListView, L"group2",-1);
HIMAGE hImage = XImage_LoadFile(L"image\\111.jpg");
wchar_t buf[MAX_PATH] = { 0 };
for (int i = 0; i < 10; i++)
{
wsprintf(buf, L"group1-item-%d", i);
int index = XListView_Item_AddItemImage(hListView, group1, hImage,-1);
XListView_Item_SetText(hListView, group1, index, 1, buf);
wsprintf(buf, L"group2-item-%d", i);
index = XListView_Item_AddItemImage(hListView, group2, hImage,-1);
XListView_Item_SetText(hListView, group2, index, 1, buf);
}
XWnd_ShowWindow(hWindow, SW_SHOW);//显示窗口
XRunXCGUI(); //运行
}
XExitXCGUI(); //释放资源
return 0;
}
HIMAGE WINAPI XImage_LoadFile(const wchar_t *pFileName)
图片_加载从文件 加载图片从文件.
Definition: ImageFrame.cpp:1014
void WINAPI XExitXCGUI()
炫彩_退出 退出界面库释放资源. 不可在dllmain()中卸载, 否则会死锁
Definition: App.cpp:572
void WINAPI XRunXCGUI()
炫彩_运行 运行消息循环,当炫彩窗口数量为0时退出.
Definition: App.cpp:564
BOOL WINAPI XInitXCGUI(BOOL bD2D)
炫彩_初始化 初始化界面库.
Definition: App.cpp:557
BOOL WINAPI XListView_Item_SetText(HELE hEle, int iGroup, int iItem, int iColumn, const wchar_t *pValue)
@anchor 列表视_项置文本
Definition: ListViewUI.cpp:3446
HXCGUI WINAPI XListView_CreateAdapter(HELE hEle)
列表视_创建数据适配器 创建数据适配器,根据绑定的项模板初始化数据适配器的列(字段名); 数据适配器存储数据, UI对象根据绑定的字段名显示数据适配器中对应的数据;
Definition: ListViewUI.cpp:2734
HELE WINAPI XListView_Create(int x, int y, int cx, int cy, HXCGUI hParent)
列表视_创建 创建列表视图元素.
Definition: ListViewUI.cpp:2671
int WINAPI XListView_Item_AddItemImage(HELE hEle, int iGroup, HIMAGE hImage, int iPos)
@anchor 列表视_项添加图片
Definition: ListViewUI.cpp:3419
int WINAPI XListView_Group_AddItemText(HELE hEle, const wchar_t *pValue, int iPos)
@anchor 列表视_组添加项文本
Definition: ListViewUI.cpp:3212
BOOL WINAPI XListView_SetItemTemplateXML(HELE hEle, const wchar_t *pXmlFile)
列表视_置项模板文件 置项模板文件.
Definition: ListViewUI.cpp:2763
HWINDOW WINAPI XWnd_Create(int x, int y, int cx, int cy, const wchar_t *pTitle, HWND hWndParent, int XCStyle)
窗口_创建 创建窗口
Definition: WindowUI.cpp:5964
BOOL WINAPI XWnd_ShowWindow(HWINDOW hWindow, int nCmdShow)
@窗口_显示扩展 显示隐藏及控制窗口最大化还原等
Definition: WindowUI.cpp:6387

示例代码 - 高级用法

class CMyWindowListView
{
public:
HWINDOW m_hWindow;
HELE m_hListView;
CMyWindowListView()
{
Init();
}
void Init()
{
m_hWindow = XWnd_Create(0, 0, 500, 400, L"炫彩界面库窗口",NULL, window_style_default);
m_hListView= XListView_Create(20,40,400,300,m_hWindow);
XListView_SetItemTemplateXML(m_hListView,L"xml-template\\ListView_Item.xml");
XAdListView_Group_AddColumn(hAdapter,XC_NAME3);
XAdListView_Item_AddColumn(hAdapter,XC_NAME1);
XAdListView_Item_AddColumn(hAdapter,XC_NAME2);
XListView_BindAdapter(m_hListView,hAdapter);
int group1=XAdListView_Group_AddItemText(hAdapter,L"group1",-1);
int group2=XAdListView_Group_AddItemText(hAdapter,L"group2",-1);
HIMAGE hImage=XImage_LoadFile(L"image\\111.jpg");
int index=0;
wchar_t temp[MAX_PATH]={0};
for (int i=0;i<20;i++)
{
wsprintf(temp,L"group1-item-%d",i);
index=XAdListView_Item_AddItemImage(hAdapter,group1,hImage,-1);
XAdListView_Item_SetText(hAdapter,group1,index,1,temp);
}
for (int i=0;i<20;i++)
{
wsprintf(temp,L"group2-item-%d",i);
index=XAdListView_Item_AddItemImage(hAdapter,group2,hImage,-1);
XAdListView_Item_SetText(hAdapter,group2,index,1,temp);
}
XEle_RegEventCPP(m_hListView,XE_LISTVIEW_SELECT,&CMyWindowListView::OnListViewSelect);
XEle_RegEventCPP(m_hListView,XE_LISTVIEW_EXPAND,&CMyWindowListView::OnListViewExpand);
XEle_RegEventCPP(m_hListView,XE_LISTVIEW_TEMP_CREATE,&CMyWindowListView::OnTemplateCreate);
XEle_RegEventCPP(m_hListView,XE_LISTVIEW_TEMP_DESTROY,&CMyWindowListView::OnTemplateDestroy);
XWnd_ShowWindow(m_hWindow,SW_SHOW);
}
int OnListViewSelect(int iGroup,int iItem,BOOL *pbHandled)
{
return 0;
}
int OnListViewExpand(int iGroup,BOOL bExpand,BOOL *pbHandled)
{
return 0;
}
int OnTemplateCreate(listView_item_i *pItem, int nFlag, BOOL *pbHandled)
{
return 0;
}
int OnTemplateDestroy(listView_item_i *pItem, int nFlag, BOOL *pbHandled)
{
return 0;
}
};
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI(TRUE);
CMyWindowListView MyWindow;
return 0;
}
#define XE_LISTVIEW_EXPAND
列表视元素,组展开收缩事件.
Definition: XCGUI.h:1140
#define XE_LISTVIEW_TEMP_DESTROY
列表视元素-项模板销毁, 模板复用机制需先启用;
Definition: XCGUI.h:1124
#define XE_LISTVIEW_SELECT
列表视元素,项选择事件.
Definition: XCGUI.h:1136
#define XE_LISTVIEW_TEMP_CREATE
列表视元素-项模板创建事件,模板复用机制需先启用; 替换模板无效判断nFlag,因为内部会检查模板是否改变,不用担心重复
Definition: XCGUI.h:1113
@ window_style_default
窗口样式-控制按钮: 居中 图标, 标题, 关闭按钮, 最大化按钮, 最小化按钮
Definition: XCGUI.h:398
void * HXCGUI
资源句柄
Definition: XCGUI.h:92
XEle_RegEventCPP(hEle, nEvent, memberFunction)
元素_注册事件CPP 注册元素事件,将类成员函数作为事件响应函数.函数省略元素自身句柄hEle.
int WINAPI XAdListView_Group_AddColumn(HXCGUI hAdapter, const wchar_t *pName)
数据适配器列表视_组添加列 组操作,添加数据列.
Definition: DataAdapter.cpp:1419
BOOL WINAPI XAdListView_Item_SetText(HXCGUI hAdapter, int iGroup, int iItem, int iColumn, const wchar_t *pValue)
数据适配器列表视_项置文本 项操作,数据填充指定列.
Definition: DataAdapter.cpp:1800
int WINAPI XAdListView_Item_AddItemImage(HXCGUI hAdapter, int iGroup, HIMAGE hImage, int iPos)
数据适配器列表视_添加项图片 项操作,添加项.
Definition: DataAdapter.cpp:1640
int WINAPI XAdListView_Group_AddItemText(HXCGUI hAdapter, const wchar_t *pValue, int iPos)
数据适配器列表视_添加组文本 组操作,添加组,数据默认填充到第一列.
Definition: DataAdapter.cpp:1430
int WINAPI XAdListView_Item_AddColumn(HXCGUI hAdapter, const wchar_t *pName)
数据适配器列表视_项添加列 项操作,添加列.
Definition: DataAdapter.cpp:1579
HXCGUI WINAPI XAdListView_Create()
数据适配器列表视_创建 创建列表视元素数据适配器.数据适配器存储数据, UI对象根据绑定的字段名显示数据适配器中对应的数据;
Definition: DataAdapter.cpp:1409
void WINAPI XListView_BindAdapter(HELE hEle, HXCGUI hAdapter)
列表视_绑定数据适配器 绑定数据适配器.
Definition: ListViewUI.cpp:2743

截图: