diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-11 18:50:33 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-11 18:50:33 -0500 |
| commit | 7686c6e599212a38b61134eb685c8a4929db6941 (patch) | |
| tree | 56814eb3f74826c5352e06c36bad22520f2e5fa4 /sysdata_windows.go | |
| parent | aa3e2788f3b4db21c13cf17d7d9155408d20e622 (diff) | |
Added the window creation code. Now let's hope this works...
Diffstat (limited to 'sysdata_windows.go')
| -rw-r--r-- | sysdata_windows.go | 73 |
1 files changed, 65 insertions, 8 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) { |
