Go language MessageBox Usage Example _golang

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.