Window - 阴影窗口

说明

本示例讲解炫彩阴影窗口的使用, 让读者可以使用炫彩界面库轻松实现阴影功能;

描述

本示例使用炫彩界面库提供的窗口阴影功能实现,可设置阴影的大小,深度,角大小,是否强制角为直角,及阴影的颜色;

调用该函数XWnd_SetTransparentType()设置窗口为阴影窗口,窗口被修改为分层窗口,因为只有分层样式的窗口才可以透明;

调用该函数XWnd_SetShadowInfo()设置阴影的效果;

如果想设置窗口整体的透明度,可调用该函数XWnd_SetTransparentAlpha();

示例代码

//包含炫彩界面库文件
#pragma comment(lib, "XCGUI.lib")
#include "xcgui.h"
class CWindowShadow
{
public:
HWINDOW m_hWindow;
HELE m_hSlider_shadowSize; //阴影大小
HELE m_hSlider_depth; //阴影深度
HELE m_hSlider_shadowAngle; //圆角阴影内收大小
HELE m_hBtn_Check_rightAnge; //是否强制直角
HELE m_hEditColor; //阴影颜色
int m_nShadowSize;
int m_nShadowDepth; //0-255
int m_nShadowAngleSize;
BOOL m_bRightAngle;
COLORREF m_clrShadow;
CWindowShadow()
{
m_nShadowSize=10;
m_nShadowDepth=100;
m_nShadowAngleSize=10;
m_clrShadow=COLORREF_MAKE(255,0,0,255);
m_bRightAngle=FALSE;
Init();
}
void Init()
{
m_hWindow = XWnd_Create(0, 0, 500, 400, L"炫彩界面库窗口", NULL, window_style_default);
XBtn_SetType(XBtn_Create(150, 80, 200, 25, L"炫彩界面库-窗口阴影演示(关闭)", m_hWindow),button_type_close);
XWnd_EnableDragWindow(m_hWindow,TRUE);
XWnd_SetBorderSize(m_hWindow,15,50,15,20);
// HIMAGE hImage=XImage_LoadFile(L"image\\bk.png"); //可设置背景图片
// HBKM hBkInfoM= XWnd_GetBkManager(m_hWindow);
// XBkInfoM_AddImage(hBkInfoM,window_state_flag_leave,hImage);
XWnd_SetShadowInfo(m_hWindow,m_nShadowSize,m_nShadowDepth,m_nShadowAngleSize,m_bRightAngle,m_clrShadow);
int top=150;
int left=110;
m_hSlider_shadowSize=XSliderBar_Create(left,top,300,20,m_hWindow); top+=35;
XEle_EnableBkTransparent(m_hSlider_shadowSize,TRUE);
XSliderBar_SetRange(m_hSlider_shadowSize,100);
XSliderBar_SetPos(m_hSlider_shadowSize,m_nShadowAngleSize);
m_hSlider_depth=XSliderBar_Create(left,top,300,20,m_hWindow); top+=35;
XSliderBar_SetRange(m_hSlider_depth,255);
XEle_EnableBkTransparent(m_hSlider_depth,TRUE);
XSliderBar_SetPos(m_hSlider_depth,m_nShadowDepth);
m_hSlider_shadowAngle=XSliderBar_Create(left,top,300,20,m_hWindow); top+=35;
XSliderBar_SetRange(m_hSlider_shadowAngle,255);
XEle_EnableBkTransparent(m_hSlider_shadowAngle,TRUE);
XSliderBar_SetPos(m_hSlider_shadowAngle,m_nShadowAngleSize);
m_hBtn_Check_rightAnge=XBtn_Create(left+10,top,100,20,L" 啊啊啊 ",m_hWindow); top+=35;
XEle_SetTextColor(m_hBtn_Check_rightAnge,COLORREF_MAKE(255,255,255,255));
XEle_EnableBkTransparent(m_hBtn_Check_rightAnge,TRUE);
XBtn_SetCheck(m_hBtn_Check_rightAnge,m_bRightAngle);
XBtn_SetTypeEx(m_hBtn_Check_rightAnge,button_type_check);
m_hEditColor=XEditColor_Create(left+10,top, 100,22,m_hWindow);
XEle_SetTextColor(m_hEditColor,COLORREF_MAKE(255,255,255,255));
XEle_EnableBkTransparent(m_hEditColor,TRUE);
XEle_RegEventCPP(m_hSlider_shadowSize,XE_SLIDERBAR_CHANGE,&CWindowShadow::OnSliderBarChange_ShadowSize);
XEle_RegEventCPP(m_hSlider_depth,XE_SLIDERBAR_CHANGE,&CWindowShadow::OnSliderBarChange_ShadowDepth);
XEle_RegEventCPP(m_hSlider_shadowAngle,XE_SLIDERBAR_CHANGE,&CWindowShadow::OnSliderBarChange_ShadowAngleSize);
XEle_RegEventCPP(m_hBtn_Check_rightAnge,XE_BUTTON_CHECK,&CWindowShadow::OnButtonCheck_ShadowRightAngle);
XEle_RegEventCPP1(m_hEditColor,XE_EDIT_CHANGED,&CWindowShadow::OnEditChange_ShadowColor);
XWnd_RegEventCPP(m_hWindow,WM_PAINT,&CWindowShadow::OnWndDrawWindow__);
XWnd_AdjustLayout(m_hWindow);
XWnd_ShowWindow(m_hWindow,SW_SHOW);
}
int OnSliderBarChange_ShadowSize(int pos,BOOL *pbHandled)
{
m_nShadowSize=pos;
XWnd_SetShadowInfo(m_hWindow,m_nShadowSize,m_nShadowDepth,m_nShadowAngleSize,m_bRightAngle,m_clrShadow);
XWnd_Redraw(m_hWindow);
return 0;
}
int OnSliderBarChange_ShadowDepth(int pos,BOOL *pbHandled)
{
m_nShadowDepth=pos;
XWnd_SetShadowInfo(m_hWindow,m_nShadowSize,m_nShadowDepth,m_nShadowAngleSize,m_bRightAngle,m_clrShadow);
XWnd_Redraw(m_hWindow);
return 0;
}
int OnSliderBarChange_ShadowAngleSize(int pos,BOOL *pbHandled)
{
m_nShadowAngleSize=pos;
XWnd_SetShadowInfo(m_hWindow,m_nShadowSize,m_nShadowDepth,m_nShadowAngleSize,m_bRightAngle,m_clrShadow);
XWnd_Redraw(m_hWindow);
return 0;
}
int OnButtonCheck_ShadowRightAngle(BOOL bCheck,BOOL *pbHandled)
{
m_bRightAngle=bCheck;
XWnd_SetShadowInfo(m_hWindow,m_nShadowSize,m_nShadowDepth,m_nShadowAngleSize,m_bRightAngle,m_clrShadow);
XWnd_Redraw(m_hWindow);
return 0;
}
int OnEditChange_ShadowColor(HELE hEditColor,BOOL *pbHandled)
{
m_clrShadow=XEditColor_GetColor(hEditColor);
XWnd_SetShadowInfo(m_hWindow,m_nShadowSize,m_nShadowDepth,m_nShadowAngleSize,m_bRightAngle,m_clrShadow);
XWnd_Redraw(m_hWindow);
return 0;
}
int OnWndDrawWindow__(HDRAW hDraw,BOOL *pbHandled)
{
*pbHandled=TRUE;
RECT rect;
XWnd_GetClientRect(m_hWindow,&rect);
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(250,250,250,255));
XDraw_FillRect(hDraw,&rect);
RECT rcBody;
XWnd_GetBodyRect(m_hWindow,&rcBody);
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(200,0,0,255));
XDraw_FillRect(hDraw,&rcBody);
XDraw_SetBrushColor(hDraw,COLORREF_MAKE(255,255,255,255));
int top=150;
int left=50;
int right=420;
wchar_t buf[256]={0};
XDraw_TextOutEx(hDraw,left,top+3,L"阴影大小:");
wsprintf(buf,L"%d",m_nShadowSize);
XDraw_TextOutEx(hDraw,right,top+3,buf); top+=35;
XDraw_TextOutEx(hDraw,left,top+3,L"阴影深度:");
wsprintf(buf,L"%d",m_nShadowDepth);
XDraw_TextOutEx(hDraw,right,top+3,buf); top+=35;
XDraw_TextOutEx(hDraw,left,top+3,L"角 大 小:");
wsprintf(buf,L"%d",m_nShadowAngleSize);
XDraw_TextOutEx(hDraw,right,top+3,buf); top+=35;
XDraw_TextOutEx(hDraw,left,top+3,L"直 角:");
wsprintf(buf,L"%d",m_nShadowAngleSize);
XDraw_TextOutEx(hDraw,right,top+3,buf); top+=35;
XDraw_TextOutEx(hDraw,left,top+3,L"阴影颜色:");
wsprintf(buf,L"%d",m_nShadowAngleSize);
XDraw_TextOutEx(hDraw,right,top+3,buf); top+=35;
return 0;
}
};
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI(TRUE);
CWindowShadow MyWindow;
return TRUE;
}
#define XE_BUTTON_CHECK
按钮选中事件
Definition: XCGUI.h:943
#define XE_EDIT_CHANGED
Definition: XCGUI.h:1170
#define XE_SLIDERBAR_CHANGE
滑动条元素,滑块位置改变事件.
Definition: XCGUI.h:962
@ button_type_close
窗口关闭按钮
Definition: XCGUI.h:299
@ button_type_check
多选按钮
Definition: XCGUI.h:297
@ window_style_default
窗口样式-控制按钮: 居中 图标, 标题, 关闭按钮, 最大化按钮, 最小化按钮
Definition: XCGUI.h:398
BOOL WINAPI XBtn_SetCheck(HELE hEle, BOOL bCheck)
按钮_置选中 设置选中状态.
Definition: ButtonUI.cpp:1800
void WINAPI XBtn_SetTypeEx(HELE hEle, XC_OBJECT_TYPE_EX nType)
按钮_置类型扩展 设置按钮类型并自动修改样式和文本对齐方式.
Definition: ButtonUI.cpp:1838
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_TextOutEx(HDRAW hDraw, int xStart, int yStart, const wchar_t *pString)
@绘制_文本扩展
Definition: DrawDC.cpp:3408
void WINAPI XDraw_SetBrushColor(HDRAW hDraw, COLORREF color)
绘制_置画刷颜色 设置画刷颜色.
Definition: DrawDC.cpp:2536
void WINAPI XEle_SetTextColor(HELE hEle, COLORREF color)
元素_置文本颜色 设置文本颜色.
Definition: EleUI.cpp:4328
void WINAPI XEle_EnableBkTransparent(HELE hEle, BOOL bEnable)
元素_启用背景透明 启用背景透明.
Definition: EleUI.cpp:4079
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
@ window_transparent_shadow
阴影窗口,带透明通道,边框阴影,窗口透明或半透明
Definition: XCGUI.h:1329
XEle_RegEventCPP1(hEle, nEvent, memberFunction)
元素_注册事件CPP1 注册元素事件,将类成员函数作为事件响应函数.函数不省略参数.
XWnd_RegEventCPP(hWindow, nEvent, memberFunction)
窗口_注册事件CPP 注册窗口事件,将类成员函数作为事件响应函数.函数省略参数窗口自身句柄hWindow.
XEle_RegEventCPP(hEle, nEvent, memberFunction)
元素_注册事件CPP 注册元素事件,将类成员函数作为事件响应函数.函数省略元素自身句柄hEle.
void WINAPI XSliderBar_SetRange(HELE hEle, int range)
滑动条_置范围 设置滑动范围.
Definition: SliderBarUI.cpp:523
HELE WINAPI XSliderBar_Create(int x, int y, int cx, int cy, HXCGUI hParent)
滑动条_创建 创建滑动条元素.
Definition: SliderBarUI.cpp:512
void WINAPI XSliderBar_SetPos(HELE hEle, int pos)
滑动条_置当前位置 设置当前进度点.
Definition: SliderBarUI.cpp:572
BOOL WINAPI XWnd_GetClientRect(HWINDOW hWindow, __out RECT *pRect)
窗口_取客户区坐标 获取窗口客户区坐标;如果是阴影窗口,那么不包含阴影部分.
Definition: WindowUI.cpp:6830
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_EnableDragWindow(HWINDOW hWindow, BOOL bEnable)
窗口_启用拖动窗口 启用拖动窗口.
Definition: WindowUI.cpp:6186
void WINAPI XWnd_SetShadowInfo(HWINDOW hWindow, int nSize, int nDepth, int nAngeleSize, BOOL bRightAngle, COLORREF color)
窗口_置阴影信息 设置窗口阴影信息.
Definition: WindowUI.cpp:7155
void WINAPI XWnd_SetBorderSize(HWINDOW hWindow, int left, int top, int right, int bottom)
窗口_置边大小 设置边大小.
Definition: WindowUI.cpp:6487
void WINAPI XWnd_AdjustLayout(HWINDOW hWindow)
窗口_调整布局 调整窗口布局, 当窗口显示状态才有效.
Definition: WindowUI.cpp:6718
void WINAPI XWnd_SetTransparentType(HWINDOW hWindow, window_transparent_ nType)
窗口_置透明类型 设置透明窗口,同时可以通过该函数关闭透明窗口; 而调整布局的函数应该放在 XWnd_SetTransparentType() 之后调用.
Definition: WindowUI.cpp:7121
BOOL WINAPI XWnd_ShowWindow(HWINDOW hWindow, int nCmdShow)
@窗口_显示扩展 显示隐藏及控制窗口最大化还原等
Definition: WindowUI.cpp:6387
void WINAPI XWnd_GetBodyRect(HWINDOW hWindow, __out RECT *pRect)
窗口_取Body坐标 获取body坐标.
Definition: WindowUI.cpp:6839
void WINAPI XWnd_Redraw(HWINDOW hWindow, BOOL bUpdate)
窗口_重绘 重绘窗口.
Definition: WindowUI.cpp:6075

程序截图