From 08ba4a1074fecc9bae73e6e72e0bc6162b81b344 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 11 Feb 2014 22:18:14 -0500 Subject: [PATCH] Fixed the wndproc not responding: turns out I have to have message dispatch in the UI thread... --- uitask_windows.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/uitask_windows.go b/uitask_windows.go index d944869..b1c0bfe 100644 --- a/uitask_windows.go +++ b/uitask_windows.go @@ -28,13 +28,34 @@ func ui(initDone chan error) { uitask = make(chan *uimsg) initDone <- doWindowsInit() - go msgloop() +// go msgloop() + var msg struct { + Hwnd _HWND + Message uint32 + WParam _WPARAM + LParam _LPARAM + Time uint32 + Pt _POINT + } + var _peekMessage = user32.NewProc("PeekMessageW") + const _PM_REMOVE = 0x0001 - for m := range uitask { - r1, _, err := m.call.Call(m.p...) - m.ret <- uiret{ - ret: r1, - err: err, + for { + select { + case m := <-uitask: + r1, _, err := m.call.Call(m.p...) + m.ret <- uiret{ + ret: r1, + err: err, + } + default: + // TODO figure out how to handle errors + _peekMessage.Call( + uintptr(unsafe.Pointer(&msg)), + uintptr(_NULL), + 0, + 0, + uintptr(_PM_REMOVE)) } } }