| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package main
- import (
- "os/exec"
- "syscall"
- "unsafe"
- )
- var (
- user32 = syscall.NewLazyDLL("user32.dll")
- msgBoxW = user32.NewProc("MessageBoxW")
- )
- const (
- mbOK = 0x00000000
- mbIconWarning = 0x00000030
- mbSetForeground = 0x00010000
- mbTopmost = 0x00040000
- )
- func showMessageBox(title, msg string) {
- ptitle, err := syscall.UTF16PtrFromString(title)
- if err != nil {
- return
- }
- ptext, err := syscall.UTF16PtrFromString(msg)
- if err != nil {
- return
- }
- msgBoxW.Call(0,
- uintptr(unsafe.Pointer(ptext)),
- uintptr(unsafe.Pointer(ptitle)),
- uintptr(mbOK|mbIconWarning|mbSetForeground|mbTopmost),
- )
- }
- func runNotepad(path string) {
- err := exec.Command("notepad.exe", path).Start()
- if err != nil {
- showMessageBox("错误", "无法打开记事本: "+err.Error())
- }
- }
|