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 (
2014-06-10 13:59:39 -05:00
user32 = syscall . NewLazyDLL ( "user32.dll" )
2014-02-08 22:51:11 -06:00
kernel32 = syscall . NewLazyDLL ( "kernel32.dll" )
2014-06-10 13:59:39 -05:00
gdi32 = syscall . NewLazyDLL ( "gdi32.dll" )
comctl32 * syscall . LazyDLL // comctl32 not defined here; see comctl_windows.go
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-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 )
2014-06-10 13:59:39 -05:00
short := int16 ( loword ) // convert to signed...
return int32 ( short ) // ...and sign extend
2014-03-25 14:06:43 -05:00
}
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 )
2014-06-10 13:59:39 -05:00
short := int16 ( hiword ) // convert to signed...
return int32 ( short ) // ...and sign extend
2014-03-25 14:06:43 -05:00
}
2014-02-11 17:36:13 -06:00
type _POINT struct {
2014-06-10 13:59:39 -05:00
x int32
y int32
2014-02-11 17:36:13 -06:00
}
type _RECT struct {
2014-06-10 13:59:39 -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.
2014-06-04 18:06:16 -05:00
// This is safe; see http://stackoverflow.com/questions/24022225/what-are-the-sign-extension-rules-for-calling-windows-api-functions-stdcall-t
2014-05-25 10:31:57 -05:00
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
2014-06-03 09:42:26 -05:00
// the intention is not to say utf16ToArg(toUTF16(s)) - even though it appears to work fine, that's just because the garbage collector scheduling makes it run long after we're finished; if we store these uintptrs globally instead, then things will break
2014-06-03 01:06:11 -05:00
// 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-06-03 02:19:19 -05:00
func utf16ToLPARAM ( s * uint16 ) uintptr {
return uintptr ( _LPARAM ( unsafe . Pointer ( s ) ) )
}
2014-05-26 21:36:34 -05:00
var (
_adjustWindowRectEx = user32 . NewProc ( "AdjustWindowRectEx" )
2014-06-10 13:59:39 -05:00
_createWindowEx = user32 . NewProc ( "CreateWindowExW" )
_getClientRect = user32 . NewProc ( "GetClientRect" )
_moveWindow = user32 . NewProc ( "MoveWindow" )
_setWindowPos = user32 . NewProc ( "SetWindowPos" )
_setWindowText = user32 . NewProc ( "SetWindowTextW" )
_showWindow = user32 . NewProc ( "ShowWindow" )
2014-06-10 07:34:26 -05:00
_getWindowRect = user32 . NewProc ( "GetWindowRect" )
2014-05-26 21:36:34 -05:00
)
type _MINMAXINFO struct {
2014-06-10 13:59:39 -05:00
ptReserved _POINT
ptMaxSize _POINT
ptMaxPosition _POINT
ptMinTrackSize _POINT
ptMaxTrackSize _POINT
2014-05-26 21:36:34 -05:00
}
func ( l _LPARAM ) MINMAXINFO ( ) * _MINMAXINFO {
return ( * _MINMAXINFO ) ( unsafe . Pointer ( l ) )
}