summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sysdata_windows.go73
-rw-r--r--unmigrated/painting_windows.go20
2 files changed, 65 insertions, 28 deletions
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
-}