diff options
| author | Pietro Gagliardi <[email protected]> | 2014-03-12 12:14:24 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-03-12 12:14:24 -0400 |
| commit | 2fb7056be4e26a5eecc365cd2608a8e8d552807f (patch) | |
| tree | f7be4deffa81b6a028796790500e90f66aa2932f /dialog_windows.go | |
| parent | 6eea59c30a9fb2d87f5806e6ddc12822228ac169 (diff) | |
Standardized message boxes so they appear similarly on all platforms. This shafts Windows because primary/secondary text message boxes were only added in Windows Vista, but at least MSDN provides discourse.
Diffstat (limited to 'dialog_windows.go')
| -rw-r--r-- | dialog_windows.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/dialog_windows.go b/dialog_windows.go index e189082..546c5c5 100644 --- a/dialog_windows.go +++ b/dialog_windows.go @@ -3,6 +3,7 @@ package ui import ( "fmt" + "os" "syscall" "unsafe" ) @@ -73,23 +74,25 @@ var ( _messageBox = user32.NewProc("MessageBoxW") ) -func _msgBox(lpText string, lpCaption string, uType uint32) (result int) { +func _msgBox(primarytext string, secondarytext string, uType uint32) (result int) { + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa511267.aspx says "Use task dialogs whenever appropriate to achieve a consistent look and layout. Task dialogs require Windows Vista® or later, so they aren't suitable for earlier versions of Windows. If you must use a message box, separate the main instruction from the supplemental instruction with two line breaks." + text := primarytext + "\n\n" + secondarytext r1, _, err := _messageBox.Call( uintptr(_NULL), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpText))), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpCaption))), + uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))), + uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(os.Args[0]))), uintptr(uType)) if r1 == 0 { // failure - panic(fmt.Sprintf("error displaying message box to user: %v\nstyle: 0x%08X\ntitle: %q\ntext:\n%s", err, uType, lpCaption, lpText)) + panic(fmt.Sprintf("error displaying message box to user: %v\nstyle: 0x%08X\ntitle: %q\ntext:\n%s", err, uType, os.Args[0], text)) } return int(r1) } -func msgBox(title string, text string) { +func msgBox(primarytext string, secondarytext string) { // TODO add an icon? - _msgBox(text, title, _MB_OK) + _msgBox(primarytext, secondarytext, _MB_OK) } -func msgBoxError(title string, text string) { - _msgBox(text, title, _MB_OK | _MB_ICONERROR) +func msgBoxError(primarytext string, secondarytext string) { + _msgBox(primarytext, secondarytext, _MB_OK | _MB_ICONERROR) } |
