Added the Windows message loop.

This commit is contained in:
Pietro Gagliardi 2014-02-11 18:31:24 -05:00
parent b918496ae4
commit a1344512aa
1 changed files with 38 additions and 0 deletions

View File

@ -3,6 +3,7 @@
package main
import (
"fmt"
"syscall"
"unsafe"
"runtime"
@ -27,6 +28,8 @@ func ui(initDone chan error) {
uitask = make(chan *uimsg)
initDone <- doWindowsInit()
go msgloop()
for m := range uitask {
r1, _, err := m.msg.Call(m.p...)
m.ret <- uiret{
@ -35,3 +38,38 @@ func ui(initDone chan error) {
}
}
}
var (
_dispatchMessage = user32.NewProc("DispatchMessageW")
_getMessage = user32.NewProc("GetMessageW")
_postQuitMessage = user32.NewProc("PostQuitMessage")
_sendMessage = user32.NewProc("SendMessageW")
_translateMessage = user32.NewProc("TranslateMessage")
)
func msgloop() {
var msg struct {
Hwnd _HWND
Message uint32
WParam _WPARAM
LParam _LPARAM
Time uint32
Pt _POINT
}
for {
r1, _, err := getMessage.Call(
uintptr(unsafe.Pointer(&msg)),
uintptr(_NULL),
uintptr(0),
uintptr(0))
if r1 == uintptr(getMessageFail) { // failure
panic(fmt.Sprintf("GetMessage failed: %v", err))
} else if r1 == 0 { // quit
break
}
// TODO handle potential errors in TranslateMessage() and DispatchMessage()
_translateMessage.Call(uintptr(unsafe.Pointer(&msg)))
_dispatchMessage.Call(uintptr(unsafe.Pointer(&msg)))
}
}