diff options
Diffstat (limited to 'dialog_windows.go')
| -rw-r--r-- | dialog_windows.go | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/dialog_windows.go b/dialog_windows.go index 131319d..d863f13 100644 --- a/dialog_windows.go +++ b/dialog_windows.go @@ -11,7 +11,7 @@ var ( _messageBox = user32.NewProc("MessageBoxW") ) -func _msgBox(parent *Window, primarytext string, secondarytext string, uType uint32) (result int) { +func _msgBox(parent *Window, primarytext string, secondarytext string, uType uint32) (result chan 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 if secondarytext != "" { @@ -19,36 +19,50 @@ func _msgBox(parent *Window, primarytext string, secondarytext string, uType uin } ptext := toUTF16(text) ptitle := toUTF16(os.Args[0]) - ret := make(chan uiret) - defer close(ret) parenthwnd := _HWND(_NULL) - if parent != nil { + if parent != dialogWindow { parenthwnd = parent.sysData.hwnd uType |= _MB_APPLMODAL // only for this window } else { uType |= _MB_TASKMODAL // make modal to every window in the program (they're all windows of the uitask, which is a single thread) } - uitask <- &uimsg{ - call: _messageBox, - p: []uintptr{ - uintptr(parenthwnd), - utf16ToArg(ptext), - utf16ToArg(ptitle), - uintptr(uType), - }, - ret: ret, - } - r := <-ret - if r.ret == 0 { // failure - panic(fmt.Sprintf("error displaying message box to user: %v\nstyle: 0x%08X\ntitle: %q\ntext:\n%s", r.err, uType, os.Args[0], text)) - } - return int(r.ret) + retchan := make(chan int) + go func() { + ret := make(chan uiret) + defer close(ret) + uitask <- &uimsg{ + call: _messageBox, + p: []uintptr{ + uintptr(parenthwnd), + utf16ToArg(ptext), + utf16ToArg(ptitle), + uintptr(uType), + }, + ret: ret, + } + r := <-ret + if r.ret == 0 { // failure + panic(fmt.Sprintf("error displaying message box to user: %v\nstyle: 0x%08X\ntitle: %q\ntext:\n%s", r.err, uType, os.Args[0], text)) + } + retchan <- int(r.ret) + }() + return retchan } -func msgBox(parent *Window, primarytext string, secondarytext string) { - _msgBox(parent, primarytext, secondarytext, _MB_OK) +func (w *Window) msgBox(primarytext string, secondarytext string) (done chan struct{}) { + done = make(chan struct{}) + go func() { + <-_msgBox(w, primarytext, secondarytext, _MB_OK) + done <- struct{}{} + }() + return done } -func msgBoxError(parent *Window, primarytext string, secondarytext string) { - _msgBox(parent, primarytext, secondarytext, _MB_OK | _MB_ICONERROR) +func (w *Window) msgBoxError(primarytext string, secondarytext string) (done chan struct{}) { + done = make(chan struct{}) + go func() { + <-_msgBox(w, primarytext, secondarytext, _MB_OK | _MB_ICONERROR) + done <- struct{}{} + }() + return done } |
