QQ好友列表实现演示 - 列表项模板替换.

说明

QQ好友列表实现演示, 图片及模板文件见v1.7.3下载包中

Tree_Item_group.xml

<?xml version="1.0" ?>
<xc_template_tree>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="fill" layout.height="fill" layout.space="6" layout.padding="2,2,2,2" >
<buttonUI itemID="1" alignH="left" alignV="top" width="13" height="13" expandButton="true" buttonStyle="expand" />
<shapeText itemID="2" layout.width="auto" layout.height="fill" content="{binding field=name1 source=data bSync=false}" />
</layoutEleUI>
</xc_template_tree>

Tree_Item_friend.xml

<?xml version="1.0" ?>
<xc_template_tree>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="auto" layout.height="fill" layout.space="6" layout.padding="2,2,2,2" >
<elementUI itemID="3" width="22" height="22" image="{binding field=name3 source=data bSync=false}" />
<shapeText itemID="2" layout.width="auto" layout.height="fill" content="{binding field=name1 source=data bSync=false}" />
<shapeText itemID="2" layout.width="auto" layout.height="fill" content="{binding field=name2 source=data bSync=false}" />
<elementUI itemID="3" width="28" height="16" image="{binding field=name5 source=data bSync=false}" />
</layoutEleUI>
</xc_template_tree>

Tree_Item_friend_sel.xml

<?xml version="1.0" ?>
<xc_template_tree>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="auto" layout.height="fill" layout.space="0" layout.padding="2,2,2,2" >
<elementUI itemID="3" width="48" height="48" image="{binding field=name4 source=data bSync=false}" />
<layoutEleUI layout.horizon="false" layout.alignH="left" layout.alignV="center" layout.width="auto" layout.height="fill" layout.space="0" layout.padding="2,2,2,2" >
<layoutEleUI layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="auto" layout.height="20" layout.space="6" layout.padding="2,2,2,2" >
<shapeText itemID="2" layout.width="auto" layout.height="fill" content="{binding field=name source=data bSync=false}" />
<elementUI itemID="3" width="28" height="16" image="{binding field=name5 source=data bSync=false}" />
</layoutEleUI>
<layoutEleUI layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="auto" layout.height="20" layout.space="6" layout.padding="2,2,2,2" >
<elementUI itemID="3" width="17" height="16" image="{binding field=name6 source=data bSync=false}" />
<shapeText itemID="3" layout.width="auto" layout.height="fill" content="{binding field=name2 source=data bSync=false}" />
</layoutEleUI>
</layoutEleUI>
</layoutEleUI>
</xc_template_tree>

示例代码

//包含炫彩界面库文件
#pragma comment(lib, "XCGUI.lib")
#include "xcgui.h"
class CMyWindowTree
{
public:
HWINDOW m_hWindow;
HELE m_hTree;
HIMAGE m_hVip;
HIMAGE m_hQZone;
HIMAGE m_hAvatar;
HIMAGE m_hAvatarLarge;
HTEMP m_hTemplate_group;
HTEMP m_hTemplate_item_Sel;
HTEMP m_hTemplate_item;
CMyWindowTree()
{
m_hTemplate_group = NULL;
Init();
}
void Release()
{
if (m_hTemplate_group) XTemp_Destroy(m_hTemplate_group);
}
void Init()
{
m_hWindow = XWnd_Create(0, 0, 320, 520, L"炫彩界面库窗口", NULL, window_style_default);
m_hTree = XTree_Create(20, 40, 280, 450, m_hWindow);
XTree_EnableConnectLine(m_hTree, FALSE, FALSE);
XTree_SetItemHeightDefault(m_hTree, 28, 54);
XTree_EnablemTemplateReuse(m_hTree,TRUE); //启用模板复用
m_hTemplate_group = XTemp_Load(listItemTemp_type_tree, L"xml-template\\Tree_Item_group.xml");
m_hTemplate_item_Sel = XTemp_Load(listItemTemp_type_tree, L"xml-template\\Tree_Item_friend_sel.xml");
m_hTemplate_item = XTemp_Load(listItemTemp_type_tree, L"xml-template\\Tree_Item_friend.xml");
m_hVip = XImage_LoadFile(L"QQImage\\vip.png");
m_hQZone = XImage_LoadFile(L"QQImage\\QZone.png");
m_hAvatar = XImage_LoadFile(L"QQImage\\avatar.png");
m_hAvatarLarge = XImage_LoadFile(L"QQImage\\avatar_large.png");
HXCGUI hAdapter = XAdTree_Create();
XTree_BindAdapter(m_hTree, hAdapter);
XAdTree_AddColumn(hAdapter, XC_NAME1); //昵称 分组名
XAdTree_AddColumn(hAdapter, (XC_NAME2)); //签名
XAdTree_AddColumn(hAdapter, (XC_NAME3)); //小头像
XAdTree_AddColumn(hAdapter, (XC_NAME4)); //大头像
XAdTree_AddColumn(hAdapter, (XC_NAME5)); //VIP 图标
XAdTree_AddColumn(hAdapter, (XC_NAME6)); //空间图标
wchar_t buf[256] = { 0 };
int nGroupID = 0;
int nItemID = 0;
for (int iGroup = 0; iGroup < 5; iGroup++)
{
wsprintf(buf, L"好友分组-%d", iGroup);
nGroupID = XAdTree_InsertItemText(hAdapter, buf, XC_ID_ROOT, XC_ID_LAST);
XTree_SetItemHeight(m_hTree, nGroupID, 26, 26);
for (int i = 0; i < 3; i++)
{
wsprintf(buf, L"我的好友-%d", i);
nItemID = XAdTree_InsertItemText(hAdapter, buf, nGroupID, XC_ID_LAST);
XAdTree_SetItemTextEx(hAdapter, nItemID, (XC_NAME2), L"我的个性签名!");
XAdTree_SetItemImageEx(hAdapter, nItemID, (XC_NAME5), m_hVip);
XAdTree_SetItemImageEx(hAdapter, nItemID, (XC_NAME6), m_hQZone);
XAdTree_SetItemImageEx(hAdapter, nItemID, (XC_NAME3), m_hAvatar);
XAdTree_SetItemImageEx(hAdapter, nItemID, (XC_NAME4), m_hAvatarLarge);
}
}
XEle_RegEventCPP(m_hTree, XE_TREE_SELECT, &CMyWindowTree::OnTreeSelect);
XEle_RegEventCPP(m_hTree, XE_TREE_EXPAND, &CMyWindowTree::OnTreeExpand);
XEle_RegEventCPP(m_hTree, XE_TREE_TEMP_CREATE, &CMyWindowTree::OnTemplateCreate);
XEle_RegEventCPP(m_hTree, XE_TREE_TEMP_DESTROY, &CMyWindowTree::OnTemplateDestroy);
XWnd_ShowWindow(m_hWindow, SW_SHOW);
}
int OnTreeSelect(int nItemID, BOOL* pbHandled)
{
return 0;
}
int OnTreeExpand(int id, BOOL bExpand, BOOL* pbHandled)
{
return 0;
}
//nFlag 0:状态改变(复用); 1:新模板实例; 2:旧模板复用
int OnTemplateCreate(tree_item_i* pItem, int nFlag, BOOL* pbHandled)
{
if (XC_ID_ERROR != XTree_GetFirstChildItem(m_hTree, pItem->nID))
{
pItem->hTemp = m_hTemplate_group;
} else if(tree_item_state_select== pItem->nState)
{
pItem->hTemp = m_hTemplate_item_Sel;
} else
{
pItem->hTemp = m_hTemplate_item;
}
*pbHandled = TRUE;
return 0;
}
int OnTemplateDestroy(tree_item_i* pItem, int nFlag, BOOL* pbHandled)
{
return 0;
}
};
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI(TRUE);
CMyWindowTree MyWindow;
MyWindow.Release();
return TRUE;
}
@ listItemTemp_type_tree
tree
Definition: XCGUI.h:1769
#define XE_TREE_EXPAND
树元素,项展开收缩事件.
Definition: XCGUI.h:1100
#define XE_TREE_TEMP_CREATE
列表树元素-项模板创建,模板复用机制需先启用; 替换模板无效判断nFlag,因为内部会检查模板是否改变,不用担心重复
Definition: XCGUI.h:1072
#define XE_TREE_SELECT
树元素,项选择事件.
Definition: XCGUI.h:1096
#define XE_TREE_TEMP_DESTROY
列表树元素-项模板销毁,模板复用机制需先启用;
Definition: XCGUI.h:1083
BOOL WINAPI XTemp_Destroy(HTEMP hTemp)
@项模板_销毁 项模板销毁
Definition: ListItemTemp.cpp:667
HTEMP WINAPI XTemp_Load(listItemTemp_type_ nType, const wchar_t *pFileName)
@项模板_加载从文件 列表项模板文件载入
Definition: ListItemTemp.cpp:65
@ window_style_default
窗口样式-控制按钮: 居中 图标, 标题, 关闭按钮, 最大化按钮, 最小化按钮
Definition: XCGUI.h:398
HIMAGE WINAPI XImage_LoadFile(const wchar_t *pFileName)
图片_加载从文件 加载图片从文件.
Definition: ImageFrame.cpp:1014
#define XC_ID_ERROR
ID错误
Definition: XCGUI.h:462
#define XC_ID_LAST
插入末尾位置(当前层)
Definition: XCGUI.h:464
#define XC_ID_ROOT
根节点
Definition: XCGUI.h:461
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
void * HXCGUI
资源句柄
Definition: XCGUI.h:92
@ tree_item_state_select
项选择状态
Definition: XCGUI.h:1475
XEle_RegEventCPP(hEle, nEvent, memberFunction)
元素_注册事件CPP 注册元素事件,将类成员函数作为事件响应函数.函数省略元素自身句柄hEle.
int WINAPI XAdTree_AddColumn(HXCGUI hAdapter, const wchar_t *pName)
数据适配器树_添加列 添加列.
Definition: DataAdapter.cpp:2944
BOOL WINAPI XAdTree_SetItemTextEx(HXCGUI hAdapter, int nID, const wchar_t *pName, const wchar_t *pValue)
数据适配器树_置项文本扩展 设置项文件内容.
Definition: DataAdapter.cpp:3056
HXCGUI WINAPI XAdTree_Create()
数据适配器树_创建 创建树元素数据适配器.数据适配器存储数据, UI对象根据绑定的字段名显示数据适配器中对应的数据;
Definition: DataAdapter.cpp:2934
BOOL WINAPI XAdTree_SetItemImageEx(HXCGUI hAdapter, int nID, const wchar_t *pName, HIMAGE hImage)
数据适配器树_置项图片扩展 设置项内容.
Definition: DataAdapter.cpp:3083
int WINAPI XAdTree_InsertItemText(HXCGUI hAdapter, const wchar_t *pValue, int nParentID, int insertID)
数据适配器树_插入项文本 插入项,数据填充到第一列.
Definition: DataAdapter.cpp:2967
int WINAPI XTree_GetFirstChildItem(HELE hEle, int nID)
列表树_取第一个子项 获取第一个子项.
Definition: TreeUI.cpp:2397
void WINAPI XTree_SetItemHeightDefault(HELE hEle, int nHeight, int nSelHeight)
列表树_置项默认高度 设置项默认高度.
Definition: TreeUI.cpp:2515
void WINAPI XTree_BindAdapter(HELE hEle, HXCGUI hAdapter)
列表树_绑定数据适配器 绑定数据适配器.
Definition: TreeUI.cpp:2458
HELE WINAPI XTree_Create(int x, int y, int cx, int cy, HXCGUI hParent)
列表树_创建 创建树元素.
Definition: TreeUI.cpp:2050
void WINAPI XTree_SetItemHeight(HELE hEle, int nID, int nHeight, int nSelHeight)
列表树_置项高度 设置指定项高度.
Definition: TreeUI.cpp:2536
void WINAPI XTree_EnableConnectLine(HELE hEle, BOOL bEnable, BOOL bSolid)
列表树_启用连接线 启用或禁用显示项的连接线.
Definition: TreeUI.cpp:2104
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

程序截图