Added the window creation code. Now let's hope this works...

This commit is contained in:
Pietro Gagliardi 2014-02-11 18:50:33 -05:00
parent aa3e2788f3
commit 7686c6e599
2 changed files with 65 additions and 28 deletions

View File

@ -2,6 +2,7 @@
package main package main
import ( import (
"fmt"
"syscall" "syscall"
"unsafe" "unsafe"
) )
@ -11,6 +12,7 @@ type sysData struct {
hwnd _HWND hwnd _HWND
cid _HMENU cid _HMENU
shownAlready bool
} }
type classData struct { type classData struct {
@ -25,8 +27,8 @@ type classData struct {
var classTypes = [nctypes]*classData{ var classTypes = [nctypes]*classData{
c_window: &classData{ c_window: &classData{
name: uintptr(unsafe.Pointer(stdWndClass)), name: uintptr(unsafe.Pointer(stdWndClass)),
style: xxxx, style: _WS_OVERLAPPEDWINDOW,
xstyle: xxxx, xstyle: 0,
}, },
// c_button: &classData{ // c_button: &classData{
// name: uintptr(unsafe.Pointer("BUTTON")) // name: uintptr(unsafe.Pointer("BUTTON"))
@ -36,21 +38,76 @@ var classTypes = [nctypes]*classData{
} }
func (s *sysData) make() (err error) { func (s *sysData) make() (err error) {
ret := make(chan uiret)
defer close(ret)
ct := classTypes[s.ctype]
uitask <- &uimsg{
call: _createWindowEx,
p: []uintptr{
uintptr(ct.xstyle),
ct.name,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s.title))),
uintptr(ct.style),
uintptr(_CW_USEDEFAULT), // TODO
uintptr(_CW_USEDEFAULT),
uintptr(_CW_USEDEFAULT),
uintptr(_CW_USEDEFAULT),
uintptr(_NULL), // TODO parent
uintptr(s.cid),
uintptr(hInstance),
uintptr(_NULL),
},
ret: ret
}
r := <-ret
if r.err != nil {
return r.err
}
s.hwnd = _HWND(r.ret)
return nil
} }
var (
_updateWindow = user32.NewProc("UpdateWindow")
)
// if the object is a window, we need to do the following the first time
// ShowWindow(hwnd, nCmdShow);
// UpdateWindow(hwnd);
// otherwise we go ahead and show the object normally with SW_SHOW
func (s *sysData) show() (err error) { func (s *sysData) show() (err error) {
if s.ctype != c_window { // don't do the init ShowWindow/UpdateWindow chain on non-windows
s.shownAlready = true
}
show := uintptr(_SW_SHOW)
if !s.shownAlready {
show = uintptr(nCmdShow)
}
ret := make(chan uiret) ret := make(chan uiret)
defer close(ret) defer close(ret)
uitask <- &uimsg{ uitask <- &uimsg{
call: _showWindow, call: _showWindow,
p: []uintptr{uintptr(s.hwnd, _SW_SHOW}, p: []uintptr{uintptr(s.hwnd, show},
ret: ret, ret: ret,
} }
r := <-ret r := <-ret
close(ret) if r.err != nil {
return r.err return r.err
} }
if !s.shownAlready {
uitask <- &uimsg{
call: _updateWindow,
p: []uintptr{uintptr(s.hwnd)},
ret: ret,
}
r = <-ret
if r.ret == 0 { // failure
return fmt.Errorf("error updating window for the first time: %v", r.err)
}
s.shownAlready = true
}
return nil
}
func (s *sysData) hide() (err error) { func (s *sysData) hide() (err error) {
ret := make(chan uiret) ret := make(chan uiret)

View File

@ -1,20 +0,0 @@
// 9 february 2014
package main
import (
// "syscall"
// "unsafe"
)
var (
updateWindow = user32.NewProc("UpdateWindow")
)
// TODO is error handling valid here? MSDN just says zero on failure; syscall.LazyProc.Call() always returns non-nil
func UpdateWindow(hWnd HWND) (err error) {
r1, _, err := updateWindow.Call(uintptr(hWnd))
if r1 == 0 { // failure
return err
}
return nil
}