msgbox_windows.go 797 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "os/exec"
  4. "syscall"
  5. "unsafe"
  6. )
  7. var (
  8. user32 = syscall.NewLazyDLL("user32.dll")
  9. msgBoxW = user32.NewProc("MessageBoxW")
  10. )
  11. const (
  12. mbOK = 0x00000000
  13. mbIconWarning = 0x00000030
  14. mbSetForeground = 0x00010000
  15. mbTopmost = 0x00040000
  16. )
  17. func showMessageBox(title, msg string) {
  18. ptitle, err := syscall.UTF16PtrFromString(title)
  19. if err != nil {
  20. return
  21. }
  22. ptext, err := syscall.UTF16PtrFromString(msg)
  23. if err != nil {
  24. return
  25. }
  26. msgBoxW.Call(0,
  27. uintptr(unsafe.Pointer(ptext)),
  28. uintptr(unsafe.Pointer(ptitle)),
  29. uintptr(mbOK|mbIconWarning|mbSetForeground|mbTopmost),
  30. )
  31. }
  32. func runNotepad(path string) {
  33. err := exec.Command("notepad.exe", path).Start()
  34. if err != nil {
  35. showMessageBox("错误", "无法打开记事本: "+err.Error())
  36. }
  37. }