Added Stop() and implemented it on Windows.
This commit is contained in:
parent
5bc9a75f0a
commit
f36451d26e
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}))
|
||||
|
|
Loading…
Reference in New Issue