diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-12 11:29:54 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-12 11:29:54 -0400 |
| commit | b944b6d4d83115dfcbb468e01d6a2cdf34b3078e (patch) | |
| tree | 9983c3948e50f8ff58d557c276c13d25b3787706 /redo/common_windows.go | |
| parent | c55386f9295fa5c16763a2a428e8e63eba1e7c53 (diff) | |
Finished writing initial Windows implementation. Now to find out why it doesn't work...
Diffstat (limited to 'redo/common_windows.go')
| -rw-r--r-- | redo/common_windows.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/redo/common_windows.go b/redo/common_windows.go new file mode 100644 index 0000000..d2cae60 --- /dev/null +++ b/redo/common_windows.go @@ -0,0 +1,48 @@ +// 12 july 2014 + +package ui + +import ( + "fmt" + "syscall" + "unsafe" +) + +// TODO get rid of this when we actually use s_POINT somewhere +var dummyToFoolwinconstgen s_POINT + +func getWindowText(hwnd uintptr) string { + // WM_GETTEXTLENGTH and WM_GETTEXT return the count /without/ the terminating null character + // but WM_GETTEXT expects the buffer size handed to it to /include/ the terminating null character + n := f_SendMessageW(hwnd, c_WM_GETTEXTLENGTH, 0, 0) + buf := make([]uint16, int(n + 1)) + if f_SendMessageW(hwnd, c_WM_GETTEXT, + t_WPARAM(n + 1), t_LPARAM(uintptr(unsafe.Pointer(&buf[0])))) != n { + panic(fmt.Errorf("WM_GETTEXT did not copy exactly %d characters out", n)) + } + return syscall.UTF16ToString(buf) +} + +func setWindowText(hwnd uintptr, text string, errors []t_LRESULT) { + res := f_SendMessageW(hwnd, c_WM_SETTEXT, + 0, t_LPARAM(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))))) + for _, err := range errors { + if res == err { + panic(fmt.Errorf("WM_SETTEXT failed; error code %d", res)) + } + } +} + +func updateWindow(hwnd uintptr, caller string) { + res, err := f_UpdateWindow(hwnd) + if res == 0 { + panic(fmt.Errorf("error calling UpdateWindow() from %s: %v", caller, err)) + } +} + +func storelpParam(hwnd uintptr, lParam t_LPARAM) { + var cs *s_CREATESTRUCTW + + cs = (*s_CREATESTRUCTW)(unsafe.Pointer(uintptr(lParam))) + f_SetWindowLongPtrW(hwnd, c_GWLP_USERDATA, cs.lpCreateParams) +} |
