2014-07-12 10:29:54 -05:00
|
|
|
// 12 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2014-07-17 18:36:24 -05:00
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
//export xpanic
|
|
|
|
func xpanic(msg *C.char, lasterr C.DWORD) {
|
2014-07-17 22:48:44 -05:00
|
|
|
panic(fmt.Errorf("%s: %s", C.GoString(msg), syscall.Errno(lasterr)))
|
2014-07-17 18:36:24 -05:00
|
|
|
}
|
|
|
|
|
2014-08-25 00:49:11 -05:00
|
|
|
//export xpanichresult
|
|
|
|
func xpanichresult(msg *C.char, hresult C.HRESULT) {
|
|
|
|
panic(fmt.Errorf("%s; HRESULT: 0x%X", C.GoString(msg), hresult))
|
|
|
|
}
|
|
|
|
|
2014-07-17 18:36:24 -05:00
|
|
|
//export xmissedmsg
|
|
|
|
func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) {
|
|
|
|
panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f)))
|
|
|
|
}
|
2014-07-12 10:29:54 -05:00
|
|
|
|
2014-08-01 17:25:59 -05:00
|
|
|
func toUTF16(s string) C.LPWSTR {
|
|
|
|
return C.LPWSTR(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
|
2014-07-17 22:14:22 -05:00
|
|
|
}
|
|
|
|
|
2014-07-17 23:22:21 -05:00
|
|
|
func getWindowText(hwnd C.HWND) string {
|
2014-07-12 10:29:54 -05:00
|
|
|
// 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
|
2014-07-17 23:22:21 -05:00
|
|
|
n := C.getWindowTextLen(hwnd)
|
2014-07-12 10:29:54 -05:00
|
|
|
buf := make([]uint16, int(n + 1))
|
2014-07-17 22:45:12 -05:00
|
|
|
C.getWindowText(hwnd, C.WPARAM(n),
|
2014-08-01 17:25:59 -05:00
|
|
|
C.LPWSTR(unsafe.Pointer(&buf[0])))
|
2014-07-12 10:29:54 -05:00
|
|
|
return syscall.UTF16ToString(buf)
|
|
|
|
}
|