diff --git a/golang_learn/data_func/go_to_xcgui/demo01/main.go b/golang_learn/data_func/go_to_xcgui/demo01/main.go new file mode 100644 index 0000000..972c982 --- /dev/null +++ b/golang_learn/data_func/go_to_xcgui/demo01/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/twgh/xcgui/app" + "github.com/twgh/xcgui/window" + "github.com/twgh/xcgui/xcc" +) + +func main() { + // 炫彩_初始化, 参数填true是启用D2D硬件加速, 效果更好. 但xp系统不支持d2d, 这时候你就得填false来关闭d2d了 + a := app.New(true) + // 创建普通窗口, 宽300, 高200, 标题是"xcgui window", xcc.Window_Style_Default是使用默认窗口风格 + w := window.New(0, 0, 300, 200, "xcgui window", 0, xcc.Window_Style_Default) + // 显示窗口 + w.Show(true) + // 运行消息循环, 程序会被阻塞在这里不退出, 当炫彩窗口数量为0时退出 + a.Run() + // 退出界面库释放资源 + a.Exit() +} diff --git a/golang_learn/data_func/go_to_xcgui/demo02/main.go b/golang_learn/data_func/go_to_xcgui/demo02/main.go new file mode 100644 index 0000000..17f1419 --- /dev/null +++ b/golang_learn/data_func/go_to_xcgui/demo02/main.go @@ -0,0 +1,26 @@ +package main + +import ( + _ "embed" + "github.com/twgh/xcgui/app" + "github.com/twgh/xcgui/window" + "github.com/twgh/xcgui/xcc" + "os" +) + +//go:embed XCGUI.dll +var dll []byte + +func main() { + _ = os.WriteFile("xcgui.dll", dll, 0666) + // 炫彩_初始化, 参数填true是启用D2D硬件加速, 效果更好. 但xp系统不支持d2d, 这时候你就得填false来关闭d2d了 + a := app.New(true) + // 创建普通窗口, 宽300, 高200, 标题是"xcgui window", xcc.Window_Style_Default是使用默认窗口风格 + w := window.New(0, 0, 300, 200, "xcgui window", 0, xcc.Window_Style_Default) + // 显示窗口 + w.Show(true) + // 运行消息循环, 程序会被阻塞在这里不退出, 当炫彩窗口数量为0时退出 + a.Run() + // 退出界面库释放资源 + a.Exit() +} diff --git a/golang_learn/data_func/go_to_xcgui/demo03/main.go b/golang_learn/data_func/go_to_xcgui/demo03/main.go new file mode 100644 index 0000000..ddc3192 --- /dev/null +++ b/golang_learn/data_func/go_to_xcgui/demo03/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "github.com/twgh/xcgui/app" + "github.com/twgh/xcgui/window" + "github.com/twgh/xcgui/xcc" +) + +func main() { + // 炫彩_初始化, 参数填true是启用D2D硬件加速, 效果更好. 但xp系统不支持d2d, 这时候你就得填false来关闭d2d了 + a := app.New(true) + // 创建普通窗口, 宽430, 高300, 标题是"xcgui", xcc.Window_Style_Default是使用默认窗口风格, xcc.Window_Style_Drag_Window是允许拖动窗口 + w := window.New(0, 0, 430, 300, "xcgui", 0, xcc.Window_Style_Default|xcc.Window_Style_Drag_Window) + + // 设置窗口边框大小:标题栏高度34 + w.SetBorderSize(0, 34, 0, 0) + // 设置窗口透明类型:阴影窗口, 带透明通道, 边框阴影, 窗口透明或半透明 + w.SetTransparentType(xcc.Window_Transparent_Shadow) + // 设置窗口透明度:255就是不透明 + w.SetTransparentAlpha(255) + // 设置窗口阴影:阴影大小8, 深度255, 圆角内收大小10, 是否强制直角false, 阴影颜色0也就是黑色 + w.SetShadowInfo(8, 255, 10, false, 0) + + // 显示窗口 + w.Show(true) + // 运行消息循环, 程序会被阻塞在这里不退出, 当炫彩窗口数量为0时退出 + a.Run() + // 退出界面库释放资源 + a.Exit() +} diff --git a/golang_learn/data_func/go_to_xcgui/demo04/1.ico b/golang_learn/data_func/go_to_xcgui/demo04/1.ico new file mode 100644 index 0000000..4e90a21 Binary files /dev/null and b/golang_learn/data_func/go_to_xcgui/demo04/1.ico differ diff --git a/golang_learn/data_func/go_to_xcgui/demo04/main.go b/golang_learn/data_func/go_to_xcgui/demo04/main.go new file mode 100644 index 0000000..4b70bbf --- /dev/null +++ b/golang_learn/data_func/go_to_xcgui/demo04/main.go @@ -0,0 +1,61 @@ +package main + +import ( + _ "embed" + "github.com/twgh/xcgui/app" + "github.com/twgh/xcgui/widget" + "github.com/twgh/xcgui/window" + "github.com/twgh/xcgui/xc" + "github.com/twgh/xcgui/xcc" +) + +//go:embed 1.ico +var icon []byte + +// 窗口图标句柄 +var hIcon = 0 + +func main() { + // 炫彩_初始化, 参数填true是启用D2D硬件加速, 效果更好. 但xp系统不支持d2d, 这时候你就得填false来关闭d2d了 + a := app.New(true) + // 创建普通窗口, 宽430, 高300, 标题是"xcgui", xcc.Window_Style_Default是使用默认窗口风格, xcc.Window_Style_Drag_Window是允许拖动窗口 + w := window.New(0, 0, 430, 300, "xcgui", 0, xcc.Window_Style_Default|xcc.Window_Style_Drag_Window) + + // 设置窗口边框大小:标题栏高度34 + w.SetBorderSize(0, 34, 0, 0) + // 设置窗口透明类型:阴影窗口, 带透明通道, 边框阴影, 窗口透明或半透明 + w.SetTransparentType(xcc.Window_Transparent_Shadow) + // 设置窗口透明度:255就是不透明 + w.SetTransparentAlpha(255) + // 设置窗口阴影:阴影大小8, 深度255, 圆角内收大小10, 是否强制直角false, 阴影颜色0也就是黑色 + w.SetShadowInfo(8, 255, 10, false, 0) + + // 从内存加载图片自适应大小 + hIcon = xc.XImage_LoadMemoryAdaptive(icon, 0, 0, 0, 0) + // 因为下面写信息框还要用, 所以这里禁止图片自动销毁, 这样就可以复用了, 否则用过之后它会自动释放掉的 + xc.XImage_EnableAutoDestroy(hIcon, false) + // 设置窗口图标 + w.SetIcon(hIcon) + + // 创建按钮 + btn := widget.NewButton(20, 50, 100, 30, "MessageBox", w.Handle) + // 注册按钮事件 + btn.Event_BnClick(func(pbHandled *bool) int { + // 创建信息框, 本质是一个模态窗口 + hWindow := a.Msg_Create("标题", "内容", xcc.MessageBox_Flag_Ok|xcc.MessageBox_Flag_Icon_Info, w.GetHWND(), xcc.Window_Style_Modal) + // 设置窗口边框大小 + xc.XWnd_SetBorderSize(hWindow, 1, 34, 1, 1) + // 设置窗口图标 + xc.XWnd_SetIcon(hWindow, hIcon) + // 显示模态窗口 + xc.XModalWnd_DoModal(hWindow) + return 0 + }) + + // 显示窗口 + w.Show(true) + // 运行消息循环, 程序会被阻塞在这里不退出, 当炫彩窗口数量为0时退出 + a.Run() + // 退出界面库释放资源 + a.Exit() +} diff --git a/golang_learn/data_func/go_to_xcgui/demo05/1.ico b/golang_learn/data_func/go_to_xcgui/demo05/1.ico new file mode 100644 index 0000000..4e90a21 Binary files /dev/null and b/golang_learn/data_func/go_to_xcgui/demo05/1.ico differ diff --git a/golang_learn/data_func/go_to_xcgui/demo05/main.go b/golang_learn/data_func/go_to_xcgui/demo05/main.go new file mode 100644 index 0000000..52df1e4 --- /dev/null +++ b/golang_learn/data_func/go_to_xcgui/demo05/main.go @@ -0,0 +1,45 @@ +package main + +import ( + _ "embed" + "github.com/twgh/xcgui/app" + "github.com/twgh/xcgui/window" + "github.com/twgh/xcgui/xc" + "github.com/twgh/xcgui/xcc" +) + +//go:embed 1.ico +var icon []byte + +// 窗口图标句柄 +var hIcon = 0 + +func main() { + // 炫彩_初始化, 参数填true是启用D2D硬件加速, 效果更好. 但xp系统不支持d2d, 这时候你就得填false来关闭d2d了 + a := app.New(true) + // 创建普通窗口, 宽430, 高300, 标题是"xcgui", xcc.Window_Style_Default是使用默认窗口风格, xcc.Window_Style_Drag_Window是允许拖动窗口 + w := window.New(0, 0, 430, 300, "xcgui", 0, xcc.Window_Style_Default|xcc.Window_Style_Drag_Window) + + // 设置窗口边框大小:标题栏高度34 + w.SetBorderSize(0, 34, 0, 0) + // 设置窗口透明类型:阴影窗口, 带透明通道, 边框阴影, 窗口透明或半透明 + w.SetTransparentType(xcc.Window_Transparent_Shadow) + // 设置窗口透明度:255就是不透明 + w.SetTransparentAlpha(255) + // 设置窗口阴影:阴影大小8, 深度255, 圆角内收大小10, 是否强制直角false, 阴影颜色0也就是黑色 + w.SetShadowInfo(8, 255, 10, false, 0) + + // 从内存加载图片自适应大小 + hIcon = xc.XImage_LoadMemoryAdaptive(icon, 0, 0, 0, 0) + // 因为下面写信息框还要用, 所以这里禁止图片自动销毁, 这样就可以复用了, 否则用过之后它会自动释放掉的 + xc.XImage_EnableAutoDestroy(hIcon, false) + // 设置窗口图标 + w.SetIcon(hIcon) + + // 显示窗口 + w.Show(true) + // 运行消息循环, 程序会被阻塞在这里不退出, 当炫彩窗口数量为0时退出 + a.Run() + // 退出界面库释放资源 + a.Exit() +} diff --git a/golang_learn/data_func/go_to_xcgui/main01/main.go b/golang_learn/data_func/go_to_xcgui/main01/main.go new file mode 100644 index 0000000..b1b2272 --- /dev/null +++ b/golang_learn/data_func/go_to_xcgui/main01/main.go @@ -0,0 +1,30 @@ +package main + +import ( + _ "embed" + "github.com/twgh/xcgui/app" + "github.com/twgh/xcgui/window" + "github.com/twgh/xcgui/xc" + "github.com/twgh/xcgui/xcc" +) + +//go:embed XCGUI.dll +var dll []byte + +func main() { + // 把 xcgui.dll 写出到windows临时目录 + err := xc.WriteDll(dll) + if err != nil { + panic(err) + } + // 炫彩_初始化, 参数填true是启用D2D硬件加速, 效果更好. 但xp系统不支持d2d, 这时候你就得填false来关闭d2d了 + a := app.New(true) + // 创建普通窗口, 宽300, 高200, 标题是"xcgui window", xcc.Window_Style_Default是使用默认窗口风格 + w := window.New(0, 0, 300, 200, "xcgui window", 0, xcc.Window_Style_Default) + // 显示窗口 + w.Show(true) + // 运行消息循环, 程序会被阻塞在这里不退出, 当炫彩窗口数量为0时退出 + a.Run() + // 退出界面库释放资源 + a.Exit() +} diff --git a/golang_learn/data_func/go_to_xcgui/main02/demo.zip b/golang_learn/data_func/go_to_xcgui/main02/demo.zip new file mode 100644 index 0000000..506f2e8 Binary files /dev/null and b/golang_learn/data_func/go_to_xcgui/main02/demo.zip differ diff --git a/golang_learn/data_func/go_to_xcgui/main02/main.go b/golang_learn/data_func/go_to_xcgui/main02/main.go new file mode 100644 index 0000000..f3b91bf --- /dev/null +++ b/golang_learn/data_func/go_to_xcgui/main02/main.go @@ -0,0 +1,39 @@ +package main + +import ( + _ "embed" + "github.com/twgh/xcgui/app" + "github.com/twgh/xcgui/widget" + "github.com/twgh/xcgui/window" + "github.com/twgh/xcgui/xc" +) + +// TODO 失败 +//go:embed XCGUI.dll +var dll []byte + +//go:embed demo.zip +var zip []byte + +func main() { + // 把 xcgui.dll 写出到windows临时目录 + _ = xc.WriteDll(dll) + a := app.New(true) + // 创建窗口从内存压缩包中的布局文件 + w := window.NewByLayoutZipMem(zip, "main.xml", "123456", 0, 0) + + // 获取窗口布局文件中的按钮 + btn := widget.NewButtonByName("viviman") + // 注册按钮被单击事件 + btn.Event_BnClick(func(pbHandled *bool) int { + a.Alert("提示", btn.GetText()+"被点击") + return 0 + }) + + // 调整布局, 必须 + w.AdjustLayout() + // 显示窗口 + w.Show(true) + a.Run() + a.Exit() +} diff --git a/golang_learn/go.mod b/golang_learn/go.mod index 6bb332a..4e4e9f0 100644 --- a/golang_learn/go.mod +++ b/golang_learn/go.mod @@ -44,6 +44,7 @@ require ( github.com/temoto/robotstxt v1.1.2 // indirect github.com/tidwall/gjson v1.13.0 github.com/tidwall/sjson v1.2.4 + github.com/twgh/xcgui v1.3.360 github.com/xuri/excelize/v2 v2.5.0 github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 diff --git a/golang_learn/go.sum b/golang_learn/go.sum index 7c80e07..5a8a1f3 100644 --- a/golang_learn/go.sum +++ b/golang_learn/go.sum @@ -459,6 +459,8 @@ github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc= github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= +github.com/twgh/xcgui v1.3.360 h1:4+rFpbE3SXc8S2h3jkQDDDj3zrxXPSi5CC6jKljYfX8= +github.com/twgh/xcgui v1.3.360/go.mod h1:16uhvR074Kq1coBif0l6b40CsnwDB9bGiXnGQumi5vI= github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=