chore: 初始化仓库(零源工具箱 0.1.0 基线)
- Go 主进程 cmd/zerorigin(托盘常驻 + 触发器/规则/动作引擎) - Wails v3 设置进程 cmd/settings(独立 module) - 监督进程 cmd/watchdog(-supervise 异常重启) - 构建脚本 build.bat / NSIS 安装包 deploy/、便携版 portable/ - 架构与 MVP 计划文档 docs/、阶段 0-4 验收记录 deploy/acceptance-0-4.md
This commit is contained in:
commit
0a1c1e82ea
188 files changed
+19926
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
user32 = syscall.NewLazyDLL("user32.dll")
|
||||
shell32 = syscall.NewLazyDLL("shell32.dll")
|
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
procMessageBoxW = user32.NewProc("MessageBoxW")
|
||||
procShellExecuteW = shell32.NewProc("ShellExecuteW")
|
||||
)
|
||||
|
||||
// ShowMessageBox 显示模态消息框(单实例冲突等提示用)。
|
||||
func ShowMessageBox(title, text string) {
|
||||
titlePtr, _ := syscall.UTF16PtrFromString(title)
|
||||
textPtr, _ := syscall.UTF16PtrFromString(text)
|
||||
procMessageBoxW.Call(0, uintptr(unsafe.Pointer(textPtr)), uintptr(unsafe.Pointer(titlePtr)), 0x00000040 /* MB_ICONINFORMATION */)
|
||||
}
|
||||
|
||||
// OpenPath 用系统默认程序打开路径(目录或文件),例如 ShellExecute 打开配置目录。
|
||||
func OpenPath(path string) error {
|
||||
return OpenPathWithArgs(path, "")
|
||||
}
|
||||
|
||||
// OpenPathWithArgs 用系统默认程序打开路径,并附加命令行参数。
|
||||
// 参数为结构化字符串,不经过 cmd /c(架构文档 §9.2 约束)。
|
||||
func OpenPathWithArgs(path, args string) error {
|
||||
p, err := syscall.UTF16PtrFromString(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var argsPtr *uint16
|
||||
if args != "" {
|
||||
argsPtr, err = syscall.UTF16PtrFromString(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// ShellExecuteW(hwnd, "open", path, args, NULL, SW_SHOWNORMAL)
|
||||
r, _, _ := procShellExecuteW.Call(0, uintptr(unsafe.Pointer(openVerb())), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(argsPtr)), 0, 1)
|
||||
if r <= 32 {
|
||||
return fmt.Errorf("shell execute %q failed: code %d", path, r)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func openVerb() *uint16 {
|
||||
s, _ := syscall.UTF16PtrFromString("open")
|
||||
return s
|
||||
}
|
||||
Reference in new issue
Block a user