/**************************************************************************\
*
* Copyright (c)  炫彩界面库. All Rights Reserved.
*
* 炫彩界面库 - 官方网站 : http://www.xcgui.com
*
\**************************************************************************/
#include "stdafx.h"


/*
//列表树//////////////////////////////////////////
HELE hTree; //树资源句柄
HELE hEdit; //编辑框资源句柄
//<隐藏按钮>-按钮点击事件
BOOL CALLBACK MyEventBtnClick(HELE hEle,HELE hEventEle)
{
	//hEle:按钮资源句柄
	//判断树是否显示按钮
	if(XTree_IsButton(hTree))
		//树隐藏按钮
		XTree_EnableButton(hTree,FALSE);
	else
		//树显示按钮
		XTree_EnableButton(hTree,TRUE);
	//重绘更新树视图
	XEle_RedrawEle(hTree);
	return TRUE;
}

//隐藏连接线按钮-点击事件
BOOL CALLBACK MyEventBtnClick2(HELE hEle,HELE hEventEle)
{
	//hEle:按钮资源句柄
	//判断是否显示连接线
	if(XTree_IsLine(hTree))
		//隐藏链接线
		XTree_EnableLine(hTree,FALSE);
	else
		//显示连接线
		XTree_EnableLine(hTree,TRUE);
	//重绘更新树视图
	XEle_RedrawEle(hTree);
	return TRUE;
}

//取消根部线按钮-点击事件
BOOL CALLBACK MyEventBtnClick3(HELE hEle,HELE hEventEle)
{
	//hEle:按钮资源句柄
	//判断树是否显示根部连接线
	if(XTree_IsRootLine(hTree))
		//隐藏根部连接线
		XTree_EnableRootLine(hTree,FALSE);
	else
		//显示根部连接线
		XTree_EnableRootLine(hTree,TRUE);
	//重绘更新树视图
	XEle_RedrawEle(hTree);
	return TRUE;
}

//树列表选择事件
BOOL CALLBACK MyEventTreeChange(HELE hEle,HELE hEventEle,int id)
{
	//hEle:树资源句柄
	//id:选择项id
	//确定有选择的项
	if(id>0)
	{
		wchar_t buf[50]={0};
		//获取选择项内容
		wchar_t *pText=XTree_GetItemText(hEle,id);
		wsprintf(buf,L"选择项:\n%s",pText);
		//设置编辑框内容
		XEdit_SetText(hEdit,buf);
	}else
	{
		XEdit_SetText(hEdit,L"没有选择项");
	}
	return TRUE;
}

//树项展开或收缩事件
BOOL CALLBACK MyEventTreeExpand(HELE hEle,HELE hEventEle,int id,BOOL bExpand)
{
	//hEle:树资源句柄
	//id:选择项id
	wchar_t buf[50]={0};
	//获取选择项内容
	wchar_t *pText=XTree_GetItemText(hEle,id);
	if(bExpand)
		wsprintf(buf,L"展开项:\n%s",pText);
	else
		wsprintf(buf,L"收缩项:\n%s",pText);
	//设置编辑框内容
	XEdit_SetText(hEdit,buf);
	return TRUE;
}

//程序入口函数
int APIENTRY _tWinMain(HINSTANCE hInstance,  HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	//初始化界面库
	XInitXCGUI();
	//创建窗口
	HWINDOW hWindow=XWnd_CreateWindow(500,200,400,260,L"测试窗口");
	ShowWindow(XWnd_GetHWnd(hWindow),SW_SHOW);
	//创建图标列表
	HXCGUI hImageList=XImageList_Create(16,16);
	//添加图片资源
	XImageList_AddImage(hImageList,XImage_LoadFile(L"image/2063.ico"));
	XImageList_AddImage(hImageList,XImage_LoadFile(L"image/2050.ico"));
	XImageList_AddImage(hImageList,XImage_LoadFile(L"image/2057.ico"));
	XImageList_AddImage(hImageList,XImage_LoadFile(L"image/2062.ico"));
	XImageList_EnableFixedSize(hImageList,TRUE);
	//创建树
	hTree=XTree_Create(10,10,200,200,hWindow);
	//XTree_SetSpacingLeft(hTree,10);   //设置左间隔
	//XTree_SetSpacingTop(hTree,10);    //设置上间隔
	//树关联图片列表
	XTree_SetImageList(hTree,hImageList);
	//插入树项
	//XTree_InsertItem(树资源句柄,内容,父项id,图片,图片,标识或id,是否展开)
	int root1=XTree_InsertItem(hTree,L"根节点项1",0,0,1);
	int root2=XTree_InsertItem(hTree,L"根节点项2",0,0,1);
	int root3=XTree_InsertItem(hTree,L"根节点项3",0,0,1);
	int root4=XTree_InsertItem(hTree,L"根节点项4",0,0,1);
	int root5=XTree_InsertItem(hTree,L"根节点项5",0,0,1);
	XTree_InsertItem(hTree,L"根节点项6",0,0,1);
	int child1=XTree_InsertItem(hTree,L"叶子项1",root1,2,3);
	XTree_InsertItem(hTree,L"叶子项2",root1,2,3);
	XTree_InsertItem(hTree,L"叶子项3",root1,2,3);
	XTree_InsertItem(hTree,L"叶子项4",child1,2,3);
	XTree_InsertItem(hTree,L"叶子项5",child1,2,3);
	XTree_InsertItem(hTree,L"叶子项6",root2,2,3);
	XTree_InsertItem(hTree,L"叶子项7",root2,2,3);
	XTree_InsertItem(hTree,L"叶子项8",root2,2,3);
	//创建按钮
	HELE hButton=XBtn_Create(220,10,80,20,L"隐藏按钮",hWindow);
	HELE hButton2=XBtn_Create(220,40,80,20,L"隐藏连接线",hWindow);
	HELE hButton3=XBtn_Create(220,70,80,20,L"取消根部线",hWindow);
	//创建编辑框
	hEdit=XEdit_Create(220,100,150,110,hWindow);
	XEdit_EnableMultiLine(hEdit,TRUE);
	//注册按钮点击事件
	XEle_RegisterEvent(hButton,XE_BNCLICK,MyEventBtnClick);
	XEle_RegisterEvent(hButton2,XE_BNCLICK,MyEventBtnClick2);
	XEle_RegisterEvent(hButton3,XE_BNCLICK,MyEventBtnClick3);
	//注册树项选择事件
	XEle_RegisterEvent(hTree,XE_TREE_SELECT,MyEventTreeChange);
	//注册树项展开收缩事件
	XEle_RegisterEvent(hTree,XE_TREE_EXPAND,MyEventTreeExpand);
	//运行程序
	XRunXCGUI();
	return 0;
}*/