summaryrefslogtreecommitdiff
path: root/common_windows.go
blob: 65f8451424fc31b9ba50e11fd3dddd7f89afd7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 7 february 2014

package ui

import (
	"syscall"
	"unsafe"
)

var (
	user32 = syscall.NewLazyDLL("user32.dll")
	kernel32 = syscall.NewLazyDLL("kernel32.dll")
	gdi32 = syscall.NewLazyDLL("gdi32.dll")
	comctl32 *syscall.LazyDLL		// comctl32 not defined here; see comctl_windows.go
	msimg32 = syscall.NewLazyDLL("msimg32.dll")
)

type _HANDLE uintptr
type _HWND _HANDLE
type _HBRUSH _HANDLE
type _HMENU _HANDLE

// 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.)
type _WPARAM uintptr
type _LPARAM uintptr
type _LRESULT uintptr

func (w _WPARAM) LOWORD() uint16 {
	// according to windef.h
	return uint16(w & 0xFFFF)
}

func (w _WPARAM) HIWORD() uint16 {
	// according to windef.h
	return uint16((w >> 16) & 0xFFFF)
}

func _LPARAMFromString(str string) _LPARAM {
	return _LPARAM(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
}

func (l _LPARAM) X() int32 {
	// according to windowsx.h
	loword := uint16(l & 0xFFFF)
	short := int16(loword)	// convert to signed...
	return int32(short)		// ...and sign extend
}

func (l _LPARAM) Y() int32 {
	// according to windowsx.h
	hiword := uint16((l & 0xFFFF0000) >> 16)
	short := int16(hiword)	// convert to signed...
	return int32(short)		// ...and sign extend
}

type _POINT struct {
	x	int32
	y	int32
}

type _RECT struct {
	left		int32
	top		int32
	right		int32
	bottom	int32
}

// 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)
}