Added Stop() and implemented it on Windows.

This commit is contained in:
Pietro Gagliardi 2014-07-13 01:14:55 -04:00
parent 5bc9a75f0a
commit f36451d26e
4 changed files with 21 additions and 2 deletions

View File

@ -26,3 +26,4 @@ package ui
// wfunc user32 SendMessageW uintptr t_UINT t_WPARAM t_LPARAM t_LRESULT,noerr
// wfunc user32 UpdateWindow uintptr uintptr
// wfunc user32 DestroyWindow uintptr uintptr
// wfunc user32 PostQuitMessage uintptr void

View File

@ -19,7 +19,19 @@ func Go() error {
return nil
}
// TODO Stop
// Stop returns a Request for package ui to stop.
// Some time after this request is received, Go() will return without performing any final cleanup.
// If Stop is issued during an event handler, it will be registered when the event handler returns.
func Stop() *Request {
c := make(chan interface{})
return &Request{
op: func() {
uistop()
c <- struct{}{}
},
resp: c,
}
}
// This is the ui main loop.
// It is spawned by Go as a goroutine.

View File

@ -45,6 +45,11 @@ func uimsgloop() {
}
}
func uistop() {
// this works fine as documented in modal loops, as modal loops are supposed to repost quit messages (http://blogs.msdn.com/b/oldnewthing/archive/2005/02/22/378018.aspx), and all the Windows internal ones do
f_PostQuitMessage(0)
}
func issue(req *Request) {
res, err := f_PostMessageW(
msgwin,

View File

@ -13,7 +13,8 @@ func init() {
go func() {
w := GetNewWindow(Do, "Hello", 320, 240)
done := make(chan struct{})
Wait(Do, w.OnClosing(func(Doer) bool {
Wait(Do, w.OnClosing(func(c Doer) bool {
Wait(c, Stop())
done <- struct{}{}
return true
}))