- 互斥体防多开/ShellExecute/窗口类名与标题查询/顶层窗口目录, 新增依赖 lxn/win - 仅 Windows, 附测试、examples/dll 例程与包 README
22 lines
752 B
Go
22 lines
752 B
Go
// Package dll 封装 Windows 系统 API(互斥体防多开、ShellExecute、窗口操作等)。
|
|
package dll
|
|
|
|
import (
|
|
"github.com/lxn/win"
|
|
"syscall"
|
|
)
|
|
|
|
// ShellExecute 调用系统 ShellExecute 打开文件/网页/程序
|
|
// dir 工作目录;file 目标(文件路径、URL 或程序);args 启动参数;hide 是否隐藏窗口
|
|
func ShellExecute(dir string, file string, args string, hide bool) bool {
|
|
lpOperation, _ := syscall.UTF16PtrFromString("open")
|
|
lpFile, _ := syscall.UTF16PtrFromString(file)
|
|
lpCwd, _ := syscall.UTF16PtrFromString(dir)
|
|
lpArgs, _ := syscall.UTF16PtrFromString(args)
|
|
showCmd := win.SW_SHOWNORMAL
|
|
if hide {
|
|
showCmd = win.SW_HIDE
|
|
}
|
|
return win.ShellExecute(0, lpOperation, lpFile, lpArgs, lpCwd, showCmd)
|
|
}
|