本帖最后由 infoyun 于 2013-4-14 21:32 编辑
infoyun自己写了一个例子,大家可以直接拷贝试用,下载试用前,请确保: 1、 你安装了vs2008 2、 你已经把炫彩的XCGUId.dll放到windows/system32下了 3、 建立了一个空的工程,里面有一个空的代码页 废话不多说,有码有真相: using System;
using System.Runtime.InteropServices;
namespace XCGUIDLLCS
{ //声明委托
public delegate void ClickDelegate(IntPtr hEle, IntPtr hEventEle); public class XCGUIDLLd
{
//全局
public class XCGlobal {
//初始化炫彩
[DllImport("XCGUId.dll", EntryPoint = "XInitXCGUI", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]//Cdecl
public static extern int XInitXCGUI(string text);//C#中string 就是unicode的,直接代替炫彩wchar_t*;炫彩的BOOL是4个字节的,直接用int代替
//运行炫彩
[DllImport("XCGUId.dll", EntryPoint = "XRunXCGUI", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void XRunXCGUI();
//消息盒子
[DllImport("XCGUId.dll", EntryPoint = "XMessageBox", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int XMessageBox(IntPtr hXCGUI, string text, string caption, int type);
}
//窗体
public class XCWindow {
//创建窗体
[DllImport("XCGUId.dll", EntryPoint = "XWnd_CreateWindow", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr XWnd_CreateWindow(int i1, int i2, int i3, int i4, string text, int hWndParent, int style);//指针或句柄用IntPtr;炫彩NULL=0,为int
//显示窗体
[DllImport("XCGUId.dll", EntryPoint = "XWnd_ShowWindow", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int XWnd_ShowWindow(IntPtr hWindow, int nCmdShow);//又是个炫彩BOOL
} //按钮
public class XCButton {
//创建按钮
[DllImport("XCGUId.dll", EntryPoint = "XBtn_Create", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr XBtn_Create(int x, int y, int cx, int cy, string title, IntPtr hParent);
} //基础元素
public class XCElement {
//注册事件
[DllImport("XCGUId.dll", EntryPoint = "XEle_RegisterEvent", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void XEle_RegisterEvent(IntPtr hEle, int type, ClickDelegate pFun);
} //点击按钮发生的事件
private static void myBtnClickEvent(IntPtr hEle, IntPtr hEventEle)
{
XCGlobal.XMessageBox(hEle, "你点了我", "提示", 2);
} /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{ XCGlobal.XInitXCGUI("hi");
//创建窗口
IntPtr hWindow = XCWindow.XWnd_CreateWindow(0, 0, 300, 200,"炫彩的世界",0,1791);
if (!hWindow.Equals(IntPtr.Zero))
{
//创建按钮
IntPtr hButton = XCButton.XBtn_Create(10, 10, 80, 25, "按钮", hWindow);
//注册按钮点击时间
XCElement.XEle_RegisterEvent(hButton, 0,myBtnClickEvent);//点击按钮事件
//显示窗口
XCWindow.XWnd_ShowWindow(hWindow, 5);
//运行
XCGlobal.XRunXCGUI();
} }
}
}
最后上个效果图:
入门第一例
|