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

#define IDB_TAB1  101
#define IDB_TAB2  102
#define IDB_TAB3  103
#define IDB_TAB4  104
#define IDB_TAB5  105
#define IDB_TAB6  106
#define IDB_TAB7  107
#define IDB_TAB8  108
#define IDB_TAB9  109

#define ID_PAGE1  3001
#define ID_PAGE2  3002
#define ID_PAGE3  3003
#define ID_PAGE4  3004
#define ID_PAGE5  3005
#define ID_PAGE6  3006
#define ID_PAGE7  3007
#define ID_PAGE8  3008
#define ID_PAGE9  3009


HELE hCurSelTab=NULL;//当前选择的TAB

BOOL CALLBACK OnMyEventTabClick(HELE hEle,HELE hEventEle) 
{
	if(hEle!=hEventEle) return FALSE;

	if(hEle==hCurSelTab)
		return FALSE;

	HELE hOldPage=(HELE)XEle_GetUserData(hCurSelTab);
	XEle_ShowEle(hOldPage,FALSE);
	XBtn_SetCheck(hCurSelTab,FALSE);


	HELE hCurSelPage=(HELE)XEle_GetUserData(hEle);
	XEle_ShowEle(hCurSelPage,TRUE);
	XBtn_SetCheck(hEle,TRUE);
	hCurSelTab=hEle;

	XWnd_ReDrawWnd(XEle_GetHWindow(hEle));

	return FALSE;
}


//测试XML布局页文件
int APIENTRY _tWinMain(HINSTANCE hInstance,  HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	XInitXCGUI(); //初始化界面库

	HXMLRES  hRes=XXmlRes_Load(L"360\\mainFrame.res");	//加载资源
	if(NULL==hRes)
	{
		MessageBox(NULL,L"加载资源失败",L"错误",0);
		return 0;
	}

	HWINDOW hWindow=XC_LoadXML_Window(L"360\\mainFrame.xml",hRes); //创建窗口
	if(NULL==hWindow)
	{
		MessageBox(NULL,L"加载XML失败",L"错误",0);
		return 0;
	}

	//加载子页
	XC_LoadXML_Page(hWindow,L"360\\mainPage2.xml",hRes);
	XC_LoadXML_Page(hWindow,L"360\\mainPage3.xml",hRes);
	XC_LoadXML_Page(hWindow,L"360\\mainPage4.xml",hRes);
	XC_LoadXML_Page(hWindow,L"360\\mainPage5.xml",hRes);
	XC_LoadXML_Page(hWindow,L"360\\mainPage6.xml",hRes);
	XC_LoadXML_Page(hWindow,L"360\\mainPage7.xml",hRes);
	XC_LoadXML_Page(hWindow,L"360\\mainPage8.xml",hRes);
	XC_LoadXML_Page(hWindow,L"360\\mainPage9.xml",hRes);

	if(FALSE==XC_LoadXML_Style(hWindow,L"360\\mainFrame.css",hRes))	//加载样式文件
	{
		MessageBox(NULL,L"加载样式失败",L"错误",0);
		return 0;
	}

	HELE hTab1=XWnd_GetEle(hWindow,IDB_TAB1);
	HELE hTab2=XWnd_GetEle(hWindow,IDB_TAB2);
	HELE hTab3=XWnd_GetEle(hWindow,IDB_TAB3);
	HELE hTab4=XWnd_GetEle(hWindow,IDB_TAB4);
	HELE hTab5=XWnd_GetEle(hWindow,IDB_TAB5);
	HELE hTab6=XWnd_GetEle(hWindow,IDB_TAB6);
	HELE hTab7=XWnd_GetEle(hWindow,IDB_TAB7);
	HELE hTab8=XWnd_GetEle(hWindow,IDB_TAB8);
	HELE hTab9=XWnd_GetEle(hWindow,IDB_TAB9);

	HELE hPage1=XWnd_GetEle(hWindow,ID_PAGE1);
	HELE hPage2=XWnd_GetEle(hWindow,ID_PAGE2);
	HELE hPage3=XWnd_GetEle(hWindow,ID_PAGE3);
	HELE hPage4=XWnd_GetEle(hWindow,ID_PAGE4);
	HELE hPage5=XWnd_GetEle(hWindow,ID_PAGE5);
	HELE hPage6=XWnd_GetEle(hWindow,ID_PAGE6);
	HELE hPage7=XWnd_GetEle(hWindow,ID_PAGE7);
	HELE hPage8=XWnd_GetEle(hWindow,ID_PAGE8);
	HELE hPage9=XWnd_GetEle(hWindow,ID_PAGE9);

	XEle_SetUserData(hTab1,(int)hPage1);

	XEle_SetUserData(hTab2,(int)hPage2);
	XEle_ShowEle(hPage2,FALSE);

	XEle_SetUserData(hTab3,(int)hPage3);
	XEle_ShowEle(hPage3,FALSE);

	XEle_SetUserData(hTab4,(int)hPage4);
	XEle_ShowEle(hPage4,FALSE);

	XEle_SetUserData(hTab5,(int)hPage5);
	XEle_ShowEle(hPage5,FALSE);

	XEle_SetUserData(hTab6,(int)hPage6);
	XEle_ShowEle(hPage6,FALSE);

	XEle_SetUserData(hTab7,(int)hPage7);
	XEle_ShowEle(hPage7,FALSE);

	XEle_SetUserData(hTab8,(int)hPage8);
	XEle_ShowEle(hPage8,FALSE);

	XEle_SetUserData(hTab9,(int)hPage9);
	XEle_ShowEle(hPage9,FALSE);

	hCurSelTab=hTab1;

	XEle_RegisterEvent(hTab1,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab2,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab3,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab4,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab5,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab6,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab7,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab8,XE_BNCLICK,OnMyEventTabClick);
	XEle_RegisterEvent(hTab9,XE_BNCLICK,OnMyEventTabClick);

	XWnd_EnableMaxButton(hWindow,FALSE);
	XWnd_SetBorderStrokeOuterColor(hWindow,RGB(102,0,0),RGB(0,0,0));
	XWnd_ShowWindow(hWindow,SW_SHOW); //显示窗口

	XXmlRes_Destroy(hRes); //不使用了销毁资源文件

	XRunXCGUI(); //运行

	return 0;
}