/
msgbox_windows.go
55 lines (49 loc) · 1.54 KB
/
msgbox_windows.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dialog
import (
"syscall"
"unsafe"
)
var (
MsgBoxBtnOk uint = 0x000000
MsgBoxBtnOkCancel uint = 0x000001
MsgBoxBtnAbortRetryIgnore uint = 0x000002
MsgBoxBtnYesNoCancel uint = 0x000003
MsgBoxBtnYesNo uint = 0x000004
MsgBoxBtnRetryCancel uint = 0x000005
MsgBoxBtnCancelTryContinue uint = 0x000006
MsgBoxIconNone uint = 0x000000
MsgBoxIconError uint = 0x000010
MsgBoxIconQuestion uint = 0x000020
MsgBoxIconWarning uint = 0x000030
MsgBoxIconInformation uint = 0x000040
MsgBoxDefaultButton1 uint = 0x000000
MsgBoxDefaultButton2 uint = 0x000100
MsgBoxDefaultButton3 uint = 0x000200
MsgBoxDefaultButton4 uint = 0x000300
MsgBoxTopMost uint = 0x041000
MsgBoxService uint = 0x200000
MsgBoxSelectOk = 1
MsgBoxSelectCancel = 2
MsgBoxSelectAbort = 3
MsgBoxSelectRetry = 4
MsgBoxSelectIgnore = 5
MsgBoxSelectYes = 6
MsgBoxSelectNo = 7
MsgBoxSelectTry = 10
MsgBoxSelectContinue = 11
)
// MsgBox create message box
func MsgBox(title string, msg string, flag uint) (int, error) {
rtn, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call(
0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(msg))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))),
uintptr(flag),
)
if rtn == 0 {
rtn, _, _ := syscall.NewLazyDLL("kernel32.dll").NewProc("GetLastError").Call()
err := MsgBoxError(uint32(rtn))
return 0, err
}
return int(rtn), nil
}