From 7686c6e599212a38b61134eb685c8a4929db6941 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 11 Feb 2014 18:50:33 -0500 Subject: [PATCH] Added the window creation code. Now let's hope this works... --- sysdata_windows.go | 73 ++++++++++++++++++++++++++++++---- unmigrated/painting_windows.go | 20 ---------- 2 files changed, 65 insertions(+), 28 deletions(-) delete mode 100644 unmigrated/painting_windows.go diff --git a/sysdata_windows.go b/sysdata_windows.go index 8cd8222..42f438d 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -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) { diff --git a/unmigrated/painting_windows.go b/unmigrated/painting_windows.go deleted file mode 100644 index 069fd2d..0000000 --- a/unmigrated/painting_windows.go +++ /dev/null @@ -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 -}