package main import ( "syscall" "unsafe" ) var ( libUser32 = syscall.NewLazyDLL("user32.dll") procMessageBoxA = libUser32.NewProc("MessageBoxA") procMessageBoxW = libUser32.NewProc("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 MessageBoxA(caption, text string, style uintptr) (result uint32) { text_, _ := syscall.BytePtrFromString(text) caption_, _ := syscall.BytePtrFromString(caption) ret, _, _ := syscall.Syscall6(procMessageBoxA.Addr(), 4, 0, uintptr(unsafe.Pointer(text_)), uintptr(unsafe.Pointer(caption_)), style, 0, 0) return uint32(ret) } func MessageBoxW(caption, text string, style uintptr) (result uint32) { text_, _ := syscall.UTF16PtrFromString(text) caption_, _ := syscall.UTF16PtrFromString(caption) ret, _, _ := syscall.Syscall6(procMessageBoxW.Addr(), 4, 0, uintptr(unsafe.Pointer(text_)), uintptr(unsafe.Pointer(caption_)), style, 0, 0) return uint32(ret) } func main() { MessageBoxA("P.Y.G", "中国飘云阁(www.chinapyg.com)", MB_OK) MessageBoxW("P.Y.G", "中国飘云阁(www.chinapyg.com)", MB_OK) }
发表评论