From c0c1e091865029aa1006602d2b195b5c6c4c8dae Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 5 Mar 2014 13:21:45 -0500 Subject: [PATCH] Have ui.Go() return on main() return on Windows. --- uitask_windows.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/uitask_windows.go b/uitask_windows.go index 33ab0ad..c8e94f2 100644 --- a/uitask_windows.go +++ b/uitask_windows.go @@ -29,6 +29,7 @@ type uiret struct { const ( _WM_APP = 0x8000 + iota msgRequested + msgQuit ) var ( @@ -49,7 +50,17 @@ func ui(main func()) error { go msgloop(threadIDReq, msglooperrs) threadID := <-threadIDReq - go main() + go func() { + main() + r1, _, err := _postThreadMessage.Call( + threadID, + msgQuit, + uintptr(0), + uintptr(0)) + if r1 == 0 { // failure + panic("error sending quit message to message loop: " + err.Error()) // TODO + } + }() quit := false for !quit { @@ -123,6 +134,11 @@ func msgloop(threadID chan uintptr, errors chan error) { } continue } + if msg.Message == msgQuit { + // does not return a value according to MSDN + _postQuitMessage.Call(0) + continue + } _translateMessage.Call(uintptr(unsafe.Pointer(&msg))) _dispatchMessage.Call(uintptr(unsafe.Pointer(&msg))) }