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
import (
"fmt"
"syscall"
"unsafe"
)
@ -9,8 +10,9 @@ import (
type sysData struct {
cSysData
hwnd _HWND
cid _HMENU
hwnd _HWND
cid _HMENU
shownAlready bool
}
type classData struct {
@ -25,8 +27,8 @@ type classData struct {
var classTypes = [nctypes]*classData{
c_window: &classData{
name: uintptr(unsafe.Pointer(stdWndClass)),
style: xxxx,
xstyle: xxxx,
style: _WS_OVERLAPPEDWINDOW,
xstyle: 0,
},
// c_button: &classData{
// name: uintptr(unsafe.Pointer("BUTTON"))
@ -36,20 +38,75 @@ var classTypes = [nctypes]*classData{
}
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) {
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)
defer close(ret)
uitask <- &uimsg{
call: _showWindow,
p: []uintptr{uintptr(s.hwnd, _SW_SHOW},
p: []uintptr{uintptr(s.hwnd, show},
ret: ret,
}
r := <-ret
close(ret)
return r.err
if r.err != nil {
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) {

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
}