-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmsgbox_windows.go
More file actions
37 lines (32 loc) · 845 Bytes
/
msgbox_windows.go
File metadata and controls
37 lines (32 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//go:build windows
package main
import (
"syscall"
"unsafe"
)
var (
user32 = syscall.NewLazyDLL("user32.dll")
messageBox = user32.NewProc("MessageBoxW")
)
// showMessage shows a native Windows message box (works even without a console).
func showMessage(title, text string) {
titlePtr, _ := syscall.UTF16PtrFromString(title)
textPtr, _ := syscall.UTF16PtrFromString(text)
messageBox.Call(
0,
uintptr(unsafe.Pointer(textPtr)),
uintptr(unsafe.Pointer(titlePtr)),
0x00000040, // MB_ICONINFORMATION
)
}
// showError shows a native Windows error message box.
func showError(title, text string) {
titlePtr, _ := syscall.UTF16PtrFromString(title)
textPtr, _ := syscall.UTF16PtrFromString(text)
messageBox.Call(
0,
uintptr(unsafe.Pointer(textPtr)),
uintptr(unsafe.Pointer(titlePtr)),
0x00000010, // MB_ICONERROR
)
}