欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Go语言MessageBox用法实例

程序员文章站 2022-05-14 20:59:57
本文实例讲述了go语言messagebox用法。分享给大家供大家参考。具体如下: 复制代码 代码如下:package main import (  &nbs...

本文实例讲述了go语言messagebox用法。分享给大家供大家参考。具体如下:

复制代码 代码如下:
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 is done.", mb_yesnocancel))
}
func init() {
       fmt.print("starting up\n")
}

希望本文所述对大家的go语言程序设计有所帮助。