The example in this article describes the go language MessageBox usage. Share to everyone for your reference. Specifically as follows:
Copy Code code as follows:
Package Main
Import (
"Syscall"
"Unsafe"
"FMT"
)
Func Abort (funcname string, err int) {
Panic (FuncName + "failed:" + syscall.) Errno (ERR). Error ())
}
VAR (
Kernel32, _ = Syscall. LoadLibrary ("Kernel32.dll")
GetModuleHandle, _ = Syscall. GetProcAddress (kernel32, "Getmodulehandlew")
User32, _ = Syscall. LoadLibrary ("User32.dll")
MessageBox, _ = Syscall. GetProcAddress (User32, "MessageBoxW")
)
Const (
MB_OK = 0x00000000
Mb_okcancel = 0x00000001
Mb_abortretryignore = 0x00000002
Mb_yesnocancel = 0x00000003
Mb_yesno = 0x00000004
Mb_retrycancel = 0x00000005
Mb_canceltrycontinue = 0x00000006
Mb_iconhand = 0x00000010
Mb_iconquestion = 0x00000020
Mb_iconexclamation = 0x00000030
Mb_iconasterisk = 0x00000040
Mb_usericon = 0x00000080
mb_iconwarning = Mb_iconexclamation
Mb_iconerror = Mb_iconhand
Mb_iconinformation = Mb_iconasterisk
Mb_iconstop = Mb_iconhand
Mb_defbutton1 = 0x00000000
Mb_defbutton2 = 0x00000100
Mb_defbutton3 = 0x00000200
Mb_defbutton4 = 0x00000300
)
Func MessageBox (caption, text string, style uintptr) (result int) {
VAR hwnd hwnd
RET, _, Callerr: = Syscall. Syscall6 (UIntPtr (MessageBox), 4,
0,//HWND
UIntPtr (unsafe. Pointer (syscall. Stringtoutf16ptr (text)),//text
UIntPtr (unsafe. Pointer (syscall. Stringtoutf16ptr (caption)),//Caption
Style,//type
0,
0)
If Callerr!= 0 {
Abort ("Call MessageBox", int (callerr))
}
result = Int (ret)
Return
}
Func Main () {
Defer syscall. FreeLibrary (KERNEL32)
Defer syscall. FreeLibrary (USER32)
Fmt. Printf ("Retern:%d\n", MessageBox ("Done Title", "this test was done.", Mb_yesnocancel))
}
Func init () {
Fmt. Print ("Starting up\n")
}
I hope this article will help you with your go language program.