msgbox_windows.go 561 B

12345678910111213141516171819
  1. package main
  2. import (
  3. "syscall"
  4. "unsafe"
  5. )
  6. // showMessageBox 调用 Windows MessageBoxW 弹出模态对话框
  7. func showMessageBox(title, msg string) {
  8. user32 := syscall.NewLazyDLL("user32.dll")
  9. msgBox := user32.NewProc("MessageBoxW")
  10. lpTitle, _ := syscall.UTF16PtrFromString(title)
  11. lpText, _ := syscall.UTF16PtrFromString(msg)
  12. // MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST
  13. const flags = 0x00000000 | 0x00000030 | 0x00010000 | 0x00040000
  14. msgBox.Call(0, uintptr(unsafe.Pointer(lpText)), uintptr(unsafe.Pointer(lpTitle)), uintptr(flags))
  15. }