2014-02-07 20:17:24 -06:00
// 7 february 2014
2014-03-12 20:55:45 -05:00
2014-02-19 10:41:10 -06:00
package ui
2014-02-07 20:17:24 -06:00
import (
"syscall"
2014-02-10 11:44:11 -06:00
"unsafe"
2014-02-07 20:17:24 -06:00
)
var (
user32 = syscall . NewLazyDLL ( "user32.dll" )
2014-02-08 22:51:11 -06:00
kernel32 = syscall . NewLazyDLL ( "kernel32.dll" )
2014-02-10 19:48:08 -06:00
gdi32 = syscall . NewLazyDLL ( "gdi32.dll" )
2014-04-02 12:47:11 -05:00
comctl32 * syscall . LazyDLL // comctl32 not defined here; see comctl_windows.go
2014-04-11 20:30:19 -05:00
msimg32 = syscall . NewLazyDLL ( "msimg32.dll" )
2014-02-07 20:17:24 -06:00
)
2014-02-11 17:36:13 -06:00
type _HANDLE uintptr
type _HWND _HANDLE
type _HBRUSH _HANDLE
type _HMENU _HANDLE
2014-02-07 20:17:24 -06:00
2014-02-15 14:41:50 -06:00
// In MSDN, _LPARAM and _LRESULT are listed as signed pointers, however their interpretation is message-specific. Ergo, just cast them yourself; it'll be the same. (Thanks to Tv` in #go-nuts for helping me realize this.)
2014-02-11 17:36:13 -06:00
type _WPARAM uintptr
type _LPARAM uintptr
type _LRESULT uintptr
2014-02-08 22:51:11 -06:00
2014-02-11 17:36:13 -06:00
func ( w _WPARAM ) LOWORD ( ) uint16 {
2014-02-10 03:59:39 -06:00
// according to windef.h
return uint16 ( w & 0xFFFF )
}
2014-02-11 17:36:13 -06:00
func ( w _WPARAM ) HIWORD ( ) uint16 {
2014-02-10 03:59:39 -06:00
// according to windef.h
return uint16 ( ( w >> 16 ) & 0xFFFF )
}
2014-02-11 17:36:13 -06:00
func _LPARAMFromString ( str string ) _LPARAM {
return _LPARAM ( unsafe . Pointer ( syscall . StringToUTF16Ptr ( str ) ) )
2014-02-10 11:44:11 -06:00
}
2014-05-25 00:03:45 -05:00
func ( l _LPARAM ) X ( ) int32 {
2014-03-25 14:06:43 -05:00
// according to windowsx.h
loword := uint16 ( l & 0xFFFF )
short := int16 ( loword ) // convert to signed...
return int32 ( short ) // ...and sign extend
}
2014-05-25 00:03:45 -05:00
func ( l _LPARAM ) Y ( ) int32 {
2014-03-25 14:06:43 -05:00
// according to windowsx.h
hiword := uint16 ( ( l & 0xFFFF0000 ) >> 16 )
short := int16 ( hiword ) // convert to signed...
return int32 ( short ) // ...and sign extend
}
2014-02-11 17:36:13 -06:00
type _POINT struct {
2014-05-11 10:11:00 -05:00
x int32
y int32
2014-02-11 17:36:13 -06:00
}
type _RECT struct {
2014-05-11 10:11:00 -05:00
left int32
top int32
right int32
bottom int32
2014-02-11 17:36:13 -06:00
}
2014-04-13 12:11:17 -05:00
2014-05-25 10:31:57 -05:00
// Go doesn't allow negative constants to be forced into unsigned types at compile-time; this will do it at runtime.
// TODO make sure sign extension works fine here (check Go's rules and ABI sign extension rules)
func negConst ( c int ) uintptr {
return uintptr ( c )
}
2014-05-26 21:36:34 -05:00
2014-06-03 01:06:11 -05:00
// the next two are convenience wrappers
// the intention is not to say utf16ToArg(toUTF16(s)) - even though it appears to work fine, that's just because the garbage collector is slow; if we store this globally then things will break
// instead, call them separately - s := toUTF16(str); winapifunc.Call(utf16ToArg(s))
func toUTF16 ( s string ) * uint16 {
return syscall . StringToUTF16Ptr ( s )
}
func utf16ToArg ( s * uint16 ) uintptr {
return uintptr ( unsafe . Pointer ( s ) )
}
2014-05-26 21:36:34 -05:00
var (
_adjustWindowRectEx = user32 . NewProc ( "AdjustWindowRectEx" )
_createWindowEx = user32 . NewProc ( "CreateWindowExW" )
_getClientRect = user32 . NewProc ( "GetClientRect" )
_moveWindow = user32 . NewProc ( "MoveWindow" )
_setWindowLong = user32 . NewProc ( "SetWindowLongW" )
_setWindowPos = user32 . NewProc ( "SetWindowPos" )
_setWindowText = user32 . NewProc ( "SetWindowTextW" )
_showWindow = user32 . NewProc ( "ShowWindow" )
)
type _MINMAXINFO struct {
ptReserved _POINT
ptMaxSize _POINT
ptMaxPosition _POINT
ptMinTrackSize _POINT
ptMaxTrackSize _POINT
}
func ( l _LPARAM ) MINMAXINFO ( ) * _MINMAXINFO {
return ( * _MINMAXINFO ) ( unsafe . Pointer ( l ) )
}