Button-按钮自绘
//包含炫彩界面库文件
#pragma comment(lib, "XCGUI.lib")
#include "xcgui.h"
HWINDOW hWindow=NULL;
HELE hButton=NULL;
//自绘事件响应
int CALLBACK OnDrawButton(HDRAW hDraw, BOOL *pbHandled)
{
*pbHandled=TRUE;
RECT rect;
XEle_GetClientRect(hButton,&rect); //获取基于左上角(0,0)坐标
//XEle_DrawEle(hButton,hDraw); //调用系统绘制
//element_state_flag_ nStateBase=XEle_GetStateFlags(hButton) //获取元素的状态
//common_state3_ nState3=XBtn_GetState(hButton); //获取按钮的3态
button_state_ nState=XBtn_GetStateEx(hButton); //获取按钮的5态
switch(nState)
{
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(250,250,250,255));
XDraw_FillRect(hDraw, &rect);
break;
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(230,230,230,255));
XDraw_FillRect(hDraw, &rect);
break;
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(210,210,210,255));
XDraw_FillRect(hDraw, &rect);
break;
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(180,180,180,255));
XDraw_FillRect(hDraw, &rect);
break;
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(100,100,100,255));
XDraw_FillRect(hDraw, &rect);
break;
}
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(200,0,0,255)); //设置文本颜色
XDraw_DrawText(hDraw,L"DrawButton",wcslen(L"DrawButton"),&rect); //绘制文本
XEle_DrawFocus(hButton,hDraw,&rect); //绘制焦点或描边
return 0; //事件的返回值
}
int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI(); //初始化
hWindow=XWnd_Create(0,0,300,200,L"炫彩界面库-窗口");//创建窗口
if(hWindow)
{
hButton=XBtn_Create(100,50,80,25,L"Button",hWindow); //创建按钮
XEle_RegEventC(hButton,XE_PAINT,OnDrawButton);//注册自绘函数
XWnd_AdjustLayout(m_hWindow);
XWnd_ShowWindow(hWindow,SW_SHOW);//显示窗口
XRunXCGUI(); //运行
}
XExitXCGUI(); //释放资源
return 0;
}
@ textAlignFlag_vcenter
垂直居中
Definition: XCGUI.h:1707
@ textAlignFlag_center
水平居中
Definition: XCGUI.h:1703
#define XE_PAINT
元素绘制事件
Definition: XCGUI.h:778
button_state_ WINAPI XBtn_GetStateEx(HELE hEle)
@按钮_取按钮状态 获取按钮状态
Definition: ButtonUI.cpp:1828
HELE WINAPI XBtn_Create(int x, int y, int cx, int cy, const wchar_t *pName, HXCGUI hParent)
按钮_创建 创建按钮元素
Definition: ButtonUI.cpp:1765
void WINAPI XDraw_FillRect(HDRAW hDraw, RECT *pRect)
@绘制_填充矩形
Definition: DrawDC.cpp:2633
void WINAPI XDraw_DrawText(HDRAW hDraw, const wchar_t *pString, int nCount, RECT *pRect)
@绘制_文本指定矩形
Definition: DrawDC.cpp:3331
void WINAPI XDraw_SetTextAlign(HDRAW hDraw, int nFlags)
绘制_置文本对齐 设置文本对齐.
Definition: DrawDC.cpp:2556
void WINAPI XDraw_SetBrushColor(HDRAW hDraw, COLORREF color)
绘制_置画刷颜色 设置画刷颜色.
Definition: DrawDC.cpp:2536
BOOL WINAPI XEle_DrawFocus(HELE hEle, HDRAW hDraw, RECT *pRect)
元素_绘制焦点 绘制元素焦点.
Definition: EleUI.cpp:4543
void WINAPI XEle_GetClientRect(HELE hEle, __out RECT *pRect)
元素_取客户区坐标 获取元素客户区坐标.
Definition: EleUI.cpp:3610
button_state_
Definition: XCGUI.h:1422
@ button_state_leave
离开状态
Definition: XCGUI.h:1424
@ button_state_check
选中状态
Definition: XCGUI.h:1430
@ button_state_stay
停留状态
Definition: XCGUI.h:1426
@ button_state_down
按下状态
Definition: XCGUI.h:1428
@ button_state_disable
禁用状态
Definition: XCGUI.h:1432
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
XEle_RegEventC(hEle, nEvent, memberFunction)
元素_注册事件C 注册元素事件, 回调函数省略元素自身句柄hEle.
HWINDOW WINAPI XWnd_Create(int x, int y, int cx, int cy, const wchar_t *pTitle, HWND hWndParent, int XCStyle)
窗口_创建 创建窗口
Definition: WindowUI.cpp:5964
void WINAPI XWnd_AdjustLayout(HWINDOW hWindow)
窗口_调整布局 调整窗口布局, 当窗口显示状态才有效.
Definition: WindowUI.cpp:6718
BOOL WINAPI XWnd_ShowWindow(HWINDOW hWindow, int nCmdShow)
@窗口_显示扩展 显示隐藏及控制窗口最大化还原等
Definition: WindowUI.cpp:6387

程序截图