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


HELE hRichEdit=NULL;
LOGFONT  Font1;
LOGFONT  Font2;
LOGFONT  Font3;
LOGFONT  Font4;
LOGFONT  Font5;
LOGFONT  Font6;
LOGFONT  Font7;

BOOL CALLBACK MyEventBtnClick(HELE hEle,HELE hEventEle) //按钮点击事件
{
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick2(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int row=0;
	int column=0;
	XRichEdit_GetCurrentPos(hRichEdit,&row,&column);
	HIMAGE hImage=XImage_LoadFile(L"image\\touxiang.jpg");
	XRichEdit_InsertImage(hRichEdit,hImage,L"image\\touxiang.jpg",row,column);
	XEle_RedrawEle(hRichEdit);
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick3(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int row=0;
	int column=0;
	XRichEdit_GetCurrentPos(hRichEdit,&row,&column);
	XRichEdit_InsertImageGif(hRichEdit,L"image\\hearts.gif",row,column);
	XEle_RedrawEle(hRichEdit);
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick4(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int row=0;
	int column=0;
	XRichEdit_GetCurrentPos(hRichEdit,&row,&column);
	XRichEdit_InsertImageGif(hRichEdit,L"image\\111.gif",row,column);
	XEle_RedrawEle(hRichEdit);
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick5(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int row=0;
	int column=0;
	XRichEdit_GetCurrentPos(hRichEdit,&row,&column);
	XRichEdit_InsertImageGif(hRichEdit,L"image\\222.gif",row,column);
	XEle_RedrawEle(hRichEdit);
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick6(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemFontEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,&Font1);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}
BOOL CALLBACK MyEventBtnClick7(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemFontEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,&Font2);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick8(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemFontEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,&Font3);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick9(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemFontEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,&Font4);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick10(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemFontEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,&Font5);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick11(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemFontEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,&Font6);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick12(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int	BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemFontEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,&Font7);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}

HELE hColor=NULL;
BOOL CALLBACK OnEventEditChange(HELE hEle,HELE hEventEle)
{
	COLORREF color=XCHColor_GetColor(hColor);

	int BeginRow=0;
	int	BeginColumn=0;
	int	EndRow=0;
	int	EndColumn=0;
	if(XRichEdit_GetSelectPos(hRichEdit,&BeginRow,&BeginColumn,&EndRow,&EndColumn))
	{
		XRichEdit_SetItemColorEx(hRichEdit,BeginRow,BeginColumn,EndRow,EndColumn,color);
		XEle_RedrawEle(hRichEdit);
	}
	return TRUE;
}

BOOL CALLBACK MyEventBtnClick1_Test(HELE hEle,HELE hEventEle) //按钮点击事件
{
	int row=0;
	int column=1;

	XRichEdit_SelectAll(hRichEdit);

	XEle_RedrawEle(hRichEdit);
	return TRUE;
}

int APIENTRY _tWinMain(HINSTANCE hInstance,  HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	XInitXCGUI();

	//创建窗口
	HWINDOW hWindow=XWnd_CreateWindow(0,0,550,450,L"炫彩界面库-窗口");
	XWnd_EnableDragBorder(hWindow,FALSE);

	HELE hButton=XBtn_Create(10,10,60,22,L"插入元素",hWindow);
	XEle_EnableEle(hButton,FALSE);
	XEle_RegisterEvent(hButton,XE_BNCLICK,MyEventBtnClick);

	HELE hButton2=XBtn_Create(80,10,60,22,L"插入图片",hWindow);
	XEle_EnableFocus(hButton2,FALSE);
	XEle_RegisterEvent(hButton2,XE_BNCLICK,MyEventBtnClick2);

	HELE hButton3=XBtn_Create(150,10,60,22,L"插入GIF",hWindow);
	XEle_EnableFocus(hButton3,FALSE);
	XEle_RegisterEvent(hButton3,XE_BNCLICK,MyEventBtnClick3);

	HELE hButton4=XBtn_Create(220,10,60,22,L"插入GIF",hWindow);
	XEle_EnableFocus(hButton4,FALSE);
	XEle_RegisterEvent(hButton4,XE_BNCLICK,MyEventBtnClick4);

	HELE hButton5=XBtn_Create(290,10,60,22,L"插入GIF",hWindow);
	XEle_EnableFocus(hButton5,FALSE);
	XEle_RegisterEvent(hButton5,XE_BNCLICK,MyEventBtnClick5);

	hRichEdit=XRichEdit_Create(10,40,390,350,hWindow); //创建RichEdit

	HELE hView=XSView_GetView(hRichEdit);
	XEle_SetBkColor(hView,RGB(220,220,220));

	//创建字体
	XC_InitFont(&Font1,L"宋体",12);
	XC_InitFont(&Font2,L"宋体",16);
	XC_InitFont(&Font3,L"宋体",20);
	XC_InitFont(&Font4,L"宋体",28);
	XC_InitFont(&Font5,L"宋体",16,TRUE);
	XC_InitFont(&Font6,L"宋体",16,FALSE,TRUE);
	XC_InitFont(&Font7,L"宋体",16,FALSE,FALSE,TRUE);

	XStatic_Create(420,30,100,20,L"设置字体:",hWindow);

	HELE hButtonFont1=XBtn_Create(420,50,100,22,L"字体 12号",hWindow);	//12
	HELE hButtonFont2=XBtn_Create(420,80,100,22,L"字体 16号",hWindow); //16
	HELE hButtonFont3=XBtn_Create(420,110,100,22,L"字体 20号",hWindow); //20
	HELE hButtonFont4=XBtn_Create(420,140,100,22,L"字体 28号",hWindow); //28

	HELE hButtonFont5=XBtn_Create(420,170,100,22,L"粗体 16号",hWindow);//粗体16号
	HELE hButtonFont6=XBtn_Create(420,200,100,22,L"斜体 16号",hWindow);//斜体16号
	HELE hButtonFont7=XBtn_Create(420,230,100,22,L"下划线 16号",hWindow);//下弧线16号

	XEle_EnableFocus(hButtonFont1,FALSE);
	XEle_EnableFocus(hButtonFont2,FALSE);
	XEle_EnableFocus(hButtonFont3,FALSE);
	XEle_EnableFocus(hButtonFont4,FALSE);
	XEle_EnableFocus(hButtonFont5,FALSE);
	XEle_EnableFocus(hButtonFont6,FALSE);
	XEle_EnableFocus(hButtonFont7,FALSE);

	XEle_RegisterEvent(hButtonFont1,XE_BNCLICK,MyEventBtnClick6);
	XEle_RegisterEvent(hButtonFont2,XE_BNCLICK,MyEventBtnClick7);
	XEle_RegisterEvent(hButtonFont3,XE_BNCLICK,MyEventBtnClick8);
	XEle_RegisterEvent(hButtonFont4,XE_BNCLICK,MyEventBtnClick9);
	XEle_RegisterEvent(hButtonFont5,XE_BNCLICK,MyEventBtnClick10);
	XEle_RegisterEvent(hButtonFont6,XE_BNCLICK,MyEventBtnClick11);
	XEle_RegisterEvent(hButtonFont7,XE_BNCLICK,MyEventBtnClick12);

	XStatic_Create(420,265,100,20,L"设置颜色:",hWindow);
	hColor=XCHColor_Create(420,290,100,22,hWindow);
	XEle_RegisterEvent(hColor,XE_EDIT_CHANGE,OnEventEditChange);

	HELE hButtonTest=XBtn_Create(420,320,100,20,L"测试",hWindow);
	XEle_EnableFocus(hButtonTest,FALSE);
	XEle_RegisterEvent(hButtonTest,XE_BNCLICK,MyEventBtnClick1_Test);

	//XRichEdit_SetText(hRichEdit,L"123456");

	XWnd_ShowWindow(hWindow,SW_SHOW);

	XRunXCGUI();

	return 0;
}


/*
//测试普通窗口
//按钮事件响应
BOOL CALLBACK My_EventBtnClick(HELE hEle,HELE hEventEle)
{
	//弹出消息框
	XMessageBox(hEle,L"你点击了按钮",L"提示",XMB_OK | XMB_CANCEL);
	return FALSE;
}

int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine, int nCmdShow)
{
	XInitXCGUI();
	
	HWINDOW hWindow=XWnd_CreateWindow(0,0,400,300,L"炫彩界面库-窗口");//创建窗口
	if(hWindow)
	{
		HELE hButton=XBtn_Create(10,10,80,25,L"按钮",hWindow);//创建按钮
		XEle_RegisterEvent(hButton,XE_BNCLICK,My_EventBtnClick);//注册按钮点击事件

		XWnd_ShowWindow(hWindow,SW_SHOW);//显示窗口

		XRunXCGUI();
	}
	return 0;
}

*/