这一节开始编写XC界面库的窗体的封装, 首先要讲解几个知识点,大家现在应该知道用directui编写的窗体程序,使用SPY++查看只会看到一个主窗体, 不会看到其他的控件,这就证明XC的主窗体应该是采用CreateWindow函数创建, 那么我们按照C# From的方式来进行封装。
首先我们要做的是将XC界面库的窗体全部函数进行C#的导出转换,转换代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace XC_Csharp.xc
{
public static class xc_window
{
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_CreateWindow(int x, int y, int cx, int cy, string pTitle, IntPtr IntPtrParent, int XCStyle);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_CreateWindowEx(int dwExStyle, string lpClassName, string lpWindowName, int dwStyle, int x, int y, int cx, int cy, IntPtr IntPtrParent, int XCStyle);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetBorderSize(IntPtr IntPtr, int left, int top, int right, int bottom);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetCaptionHeight(IntPtr IntPtr, int captionHeight);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_SetIcon(IntPtr IntPtr, IntPtr hIcon, bool bBigIcon);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_SetIcon2(IntPtr IntPtr, string pFileName, bool bBigIcon);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetIcon(IntPtr IntPtr, bool bBigIcon);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetIconSize(IntPtr IntPtr, int width, int height);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_MaximizeWnd(IntPtr IntPtr, bool bMax);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_IsMaximizeWnd(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern uint XWnd_SetTimer(IntPtr IntPtr, uint nIDEvent, uint uElapse);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_KillTimer(IntPtr IntPtr, uint nIDEvent);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern uint XWnd_SetTimerEx(IntPtr IntPtr, uint nIDEvent, uint uElapse, int userData);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_KillTimerEx(IntPtr IntPtr, uint nIDEvent);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetBkColor(IntPtr IntPtr, int color);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetMinWidth(IntPtr IntPtr, int width);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetMinHeight(IntPtr IntPtr, int height);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetRoundSize(IntPtr IntPtr, int size);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_RedrawWndRect(IntPtr IntPtr, ref RECT pRect, bool bImmediately);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_RedrawWnd(IntPtr IntPtr, bool bImmediately);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_RedrawEleRectNC(IntPtr IntPtr, IntPtr hEle, ref RECT pRect);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_GetDrawRect(IntPtr IntPtr, ref RECT pRect);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetFocusEle(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetFont(IntPtr IntPtr, IntPtr hFontX);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetFontCaptionText(IntPtr IntPtr, IntPtr hFontX);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetColorCaptionText(IntPtr IntPtr, int color);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_ShowWindow(IntPtr IntPtr, int nCmdShow);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_SetWindowPos(IntPtr IntPtr, int IntPtrInsertAfter, int x, int y, int cx, int cy, uint uFlags);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_SetWindowRect(IntPtr IntPtr, ref RECT pRect);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_SetWindowSize(IntPtr IntPtr, int width, int height);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_GetWindowRect(IntPtr IntPtr, ref RECT pRect);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_IsWindowVisible(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableDragBorder(IntPtr IntPtr, bool bDrag);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableDragWindow(IntPtr IntPtr, bool bDrag);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetButtonMin(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetButtonMax(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetButtonClose(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableMinButton(IntPtr IntPtr, bool bEnable, bool bRedraw);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableMaxButton(IntPtr IntPtr, bool bEnable, bool bRedraw);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableCloseButton(IntPtr IntPtr, bool bEnable, bool bRedraw);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableRound(IntPtr IntPtr, bool bEnable, bool bRedraw);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetChildEleCount(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetChildEleCountNC(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetChildEleByIndex(IntPtr IntPtr, int index);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetChildEleByIndexNC(IntPtr IntPtr, int index);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetTransparentFlag(IntPtr IntPtr, int flag);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetTransparentAlpha(IntPtr IntPtr, char alpha);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetTransparentColor(IntPtr IntPtr, int color);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetImage(IntPtr IntPtr, IntPtr hImage);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetImageNC(IntPtr IntPtr, IntPtr hImage);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetImageCaption(IntPtr IntPtr, IntPtr hImage);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetImageBorderLeft(IntPtr IntPtr, IntPtr hImage);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetImageBorderRight(IntPtr IntPtr, IntPtr hImage);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetImageBorderBottom(IntPtr IntPtr, IntPtr hImage);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableBorderStrokeInner(IntPtr IntPtr, bool bStroke);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_EnableBorderStrokeOuter(IntPtr IntPtr, bool bStroke);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetBorderStrokeInnerColor(IntPtr IntPtr, int color1, int color2);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetBorderStrokeOuterColor(IntPtr IntPtr, int color1, int color2);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_CloseWindow(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_CreateCaret(IntPtr IntPtr, IntPtr hEle, int width, int height);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetCaretSize(IntPtr IntPtr, int width, int height);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetCaretPos(IntPtr IntPtr, int x, int y);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetCaretPosEx(IntPtr IntPtr, int x, int y, int width, int height);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetCaretColor(IntPtr IntPtr, int color);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_ShowCaret(IntPtr IntPtr, bool bShow);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_DestroyCaret(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_GetClientRect(IntPtr IntPtr, ref RECT pRect);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_GetNCClientRect(IntPtr IntPtr, ref RECT pRect);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetClientLeft(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetClientRight(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetClientBottom(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetClientTop(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetCaptionHeight(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_WindowToClientRect(IntPtr IntPtr, ref RECT pRect);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_WindowToClientPt(IntPtr IntPtr, ref POINT pPt);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_SetUserData(IntPtr IntPtr, int data);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetUserData(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_RegisterMessage(IntPtr IntPtr, int message, IntPtr pFun);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_RegisterNCMessage(IntPtr IntPtr, int message, IntPtr pFun);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_RegisterMsgProc(IntPtr IntPtr, pFunWndMsgProc pFun);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_AddEle(IntPtr IntPtr, IntPtr hEle);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_AddEleNC(IntPtr IntPtr, IntPtr hEle);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_AddMenuBar(IntPtr IntPtr, IntPtr hEle);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_AddToolBar(IntPtr IntPtr, IntPtr hEle);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern void XWnd_Adjust(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetIntPtr(IntPtr IntPtr);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern IntPtr XWnd_GetEle(IntPtr IntPtr, int eleID);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern int XWnd_GetWindowText(IntPtr IntPtr, string pOut, int len);
[DllImport(xc_global.Name, CharSet = CharSet.Unicode)]
public static extern bool XWnd_SetWindowText(IntPtr IntPtr, string pText);
}
}
这里需要注意的是导出函数采用UNICIDE编码,因为XC全部使用的是UNICODE,不然会显示乱码。 现在我们导出的所有函数, 我们开始封装一个窗体时,我们应该构思窗体的相关组成部分,这样利于我们编写属性。
窗体的组成部分大致可以分为如下:
1、主窗体面板。
2、标题栏。
3、图标。
4、标题。
5、最大化按钮。
6、最小化按钮。
7、关闭按钮。
上面这些是一个基本窗体的组成部分, 不过现在一般市面上的软件都将窗体分的更细一点,例如XC就多出了如下部分:
1、自定义标题栏的高度,贴图。
2、自定义窗体边框的颜色,贴图。
3、窗体底部(状态栏)的贴图。
通过上面这些分析我们编写如下代码。
using System;
using System.Collections.Generic;
using System.Text;
using XC_Csharp.xc;
using System.Drawing;
using XC_Csharp.win32;
namespace XC_Csharp.xc_sharp
{
public class XCWindow:IContainControl
{
#region private members
private int _x;
private int _y;
private int _wh;
private int _he;
private string _title;
public Color _colorTitle;
private IntPtr _parent;
private IntPtr _handle;
#endregion
public XCWindow(int x, int y, int width, int heigth, string title, IntPtr hParent, int style)
{
_handle = xc_window.XWnd_CreateWindow(x, y, width, heigth, title, hParent, style);
_x = x;
_y = y;
_wh = width;
_he = heigth;
_title = title;
_parent = hParent;
}
public XCWindow(int width, int heigth, string title, IntPtr hParent, int style)
{
_handle = xc_window.XWnd_CreateWindow(0, 0, width, heigth, title, hParent, style);
_x = 0;
_y = 0;
_wh = width;
_he = heigth;
_title = title;
_parent = hParent;
}
public XCWindow(int width, int heigth, string title)
{
_handle = xc_window.XWnd_CreateWindow(0, 0, width, heigth, title, IntPtr.Zero, 1791);
_x = 0;
_y = 0;
_wh = width;
_he = heigth;
_title = title;
_parent = IntPtr.Zero;
}
#region public methods
/// <summary>
/// 显示窗体
/// </summary>
public void Show()
{
xc_window.XWnd_ShowWindow(_handle, 1);
}
/// <summary>
/// 关闭窗体
/// </summary>
public virtual void Close()
{
xc_window.XWnd_CloseWindow(_handle);
}
/// <summary>
/// 重绘窗体指定区域
/// </summary>
/// <param name="rect"></param>
public void ReDraw(RECT rect)
{
xc_window.XWnd_RedrawWndRect(_handle, ref rect, true);
}
/// <summary>
/// 重绘窗体
/// </summary>
public void ReDraw()
{
xc_window.XWnd_RedrawWnd(_handle, true);
}
#endregion
#region attribute
/// <summary>
/// 获取窗体句柄
/// </summary>
public IntPtr Handle
{
get { return _handle; }
}
/// <summary>
/// 获取或设置窗口左上角X坐标
/// </summary>
public int X
{
get { return _x; }
set
{
xc_window.XWnd_SetWindowPos(_handle, 0, value, _y, _wh, _he, 1);
_x = value;
}
}
/// <summary>
/// 获取或设置窗口左上角Y坐标
/// </summary>
public int Y
{
get { return _y; }
set
{
xc_window.XWnd_SetWindowPos(_handle, 0, _x, value, _wh, _he, 1);
_y = value;
}
}
/// <summary>
/// 获取或设置窗体宽度
/// </summary>
public int Width
{
get { return _wh; }
set
{
xc_window.XWnd_SetWindowSize(_handle, value, _he);
_wh = value;
}
}
/// <summary>
/// 设置窗体最小宽度
/// </summary>
public int MinWidth
{
set
{
xc_window.XWnd_SetMinWidth(_handle, value);
}
}
/// <summary>
/// 获取或设置窗体高度
/// </summary>
public int Heigth
{
get { return _he; }
set
{
xc_window.XWnd_SetWindowSize(_handle, _wh, value);
_he = value;
}
}
/// <summary>
/// 设置窗体最小高度
/// </summary>
public int MinHeigth
{
set
{
xc_window.XWnd_SetMinHeight(_handle, value);
}
}
/// <summary>
/// 获取或设置窗体标题
/// </summary>
public string Caption
{
get { return _title; }
set
{
xc_window.XWnd_SetWindowText(_handle, value);
_title = value;
}
}
/// <summary>
/// 设置窗体标题的字体颜色
/// </summary>
public Color CaptionColor
{
set
{
xc_window.XWnd_SetColorCaptionText(_handle, Helper.RGB(value.R, value.G, value.B));
}
}
/// <summary>
/// 设置窗体背景颜色
/// </summary>
public Color BackGroundColor
{
set
{
xc_window.XWnd_SetBkColor(_handle, Helper.RGB(value.R, value.G, value.B));
}
}
/// <summary>
/// 设置窗体状态
/// </summary>
public WindowStyle WindowStyle
{
set
{
switch (value)
{
case WindowStyle.Max:
xc_window.XWnd_MaximizeWnd(_handle, true);
break;
case WindowStyle.Min:
xc_window.XWnd_ShowWindow(_handle, 6);
break;
case WindowStyle.Normal:
xc_window.XWnd_ShowWindow(_handle, 1);
break;
}
}
}
/// <summary>
/// 获取或设置一个,该值表示是否显示窗体
/// </summary>
public bool Visible
{
get
{
return xc_window.XWnd_IsWindowVisible(_handle);
}
set
{
xc_window.XWnd_ShowWindow(_handle, value ? 1 : 0);
}
}
private bool _maximizeBox;
/// <summary>
/// 启用或禁用最大化按钮
/// </summary>
public bool MaximizeBox
{
set
{
_maximizeBox = value;
xc_window.XWnd_EnableMaxButton(_handle, value, true);
}
}
private bool _minimizeBox;
/// <summary>
/// 启用或禁用最小化按钮
/// </summary>
public bool MinimizeBox
{
set
{
_minimizeBox = value;
xc_window.XWnd_EnableMinButton(_handle, value, true);
}
}
/// <summary>
/// 设置标题栏的高度, 不显示标题栏设置为0
/// </summary>
public int CaptionHeigth
{
set
{
xc_window.XWnd_SetCaptionHeight(_handle, value);
}
}
/// <summary>
/// 设置窗体的状态,是否可拖动改变大小
/// </summary>
public FromStyle FromStyle
{
set
{
xc_window.XWnd_EnableDragBorder(_handle, value == FromStyle.Sizable);
}
}
/// <summary>
/// 背景图片路径
/// </summary>
public string BackgroundImageFromPath
{
set
{
xc_window.XWnd_SetImage(_handle, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 关闭按钮鼠标进入图片
/// </summary>
public string CloseButtonHoverImagePath
{
set
{
IntPtr handleCloseBtn = xc_window.XWnd_GetButtonClose(_handle);
xc_button.XBtn_SetImageStay(handleCloseBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 关闭按钮鼠标按下时的图片
/// </summary>
public string CloseButtonDownImagePath
{
set
{
IntPtr handleCloseBtn = xc_window.XWnd_GetButtonClose(_handle);
xc_button.XBtn_SetImageDown(handleCloseBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 关闭按钮鼠标离开时的图片
/// </summary>
public string CloseButtonLeaveImagePath
{
set
{
IntPtr handleCloseBtn = xc_window.XWnd_GetButtonClose(_handle);
xc_button.XBtn_SetImageLeave(handleCloseBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 最大化按钮鼠标进入图片
/// </summary>
public string MaxButtonHoverImagePath
{
set
{
IntPtr handleMaxBtn = xc_window.XWnd_GetButtonMax(_handle);
xc_button.XBtn_SetImageStay(handleMaxBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 最大化关闭按钮鼠标按下图片
/// </summary>
public string MaxButtonDownImagePath
{
set
{
IntPtr handleMaxBtn = xc_window.XWnd_GetButtonMax(_handle);
xc_button.XBtn_SetImageDown(handleMaxBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 最大化关闭按钮鼠标离开图片
/// </summary>
public string MaxButtonLeaveImagePath
{
set
{
IntPtr handleMaxBtn = xc_window.XWnd_GetButtonMax(_handle);
xc_button.XBtn_SetImageLeave(handleMaxBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 最小化关闭按钮鼠标进入图片
/// </summary>
public string MinButtonHoverImagePath
{
set
{
IntPtr handleMinBtn = xc_window.XWnd_GetButtonClose(_handle);
xc_button.XBtn_SetImageStay(handleMinBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 最小化关闭按钮鼠标按下图片
/// </summary>
public string MinButtonDownImagePath
{
set
{
IntPtr handleMinBtn = xc_window.XWnd_GetButtonClose(_handle);
xc_button.XBtn_SetImageDown(handleMinBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 最小化关闭按钮鼠标离开图片
/// </summary>
public string MinButtonLeaveImagePath
{
set
{
IntPtr handleMinBtn = xc_window.XWnd_GetButtonClose(_handle);
xc_button.XBtn_SetImageLeave(handleMinBtn, xc_image.XImage_LoadFile(value, true));
}
}
/// <summary>
/// 窗口标题栏图片, 仅当标题栏高度不为0时生效
/// </summary>
public string CaptionImagePath
{
set
{
xc_window.XWnd_SetImageCaption(_handle, xc_image.XImage_LoadFile(value, true));
}
}
private bool _iconBig;
/// <summary>
/// 设置一个值,该值表示是否显示大图标
/// </summary>
public bool IconBig
{
set { _iconBig = value; }
}
/// <summary>
/// 窗体图标文件路径
/// </summary>
public string IconPath
{
set
{
xc_window.XWnd_SetIcon2(_handle, value, _iconBig);
}
}
#endregion
#region IContainControl 成员
public void AddChild(Element ele)
{
ele.Create(_handle);
}
public void RemoveChild(Element ele)
{
}
#endregion
}
}
上面的代码可以看到Window继承了一个IContainControl的接口, 该接口的定义如下
public interface IContainControl
{
void AddChild(Element ele);
void RemoveChild(Element ele);
}
也就是允许窗体成为容器,能够将其他元素加入进来。
下面我们将XC的运行程序进行修改
XCAPI.GuiInit("", "C#界面库");
XCWindow window = new XCWindow(400, 300, "第一个窗体");
window.BackGroundColor = Color.White;
window.Show();
XCAPI.XRunXCGUI();
是不是代码简洁多了,更符合面向对象的思想了, 好了这一节就将到这里, 如有疑问请联系我,QQ:415641255