summaryrefslogtreecommitdiff
path: root/controls_windows.go
blob: b6a4f0389d6267cdbff23f89f3bd2b747ebcf17e (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 9 february 2014
package main

import (
//	"syscall"
//	"unsafe"
)

// Button styles.
const (
	// from winuser.h
	BS_PUSHBUTTON = 0x00000000
	BS_DEFPUSHBUTTON = 0x00000001
	BS_CHECKBOX = 0x00000002
	BS_AUTOCHECKBOX = 0x00000003
	BS_RADIOBUTTON = 0x00000004
	BS_3STATE = 0x00000005
	BS_AUTO3STATE = 0x00000006
	BS_GROUPBOX = 0x00000007
	BS_USERBUTTON = 0x00000008
	BS_AUTORADIOBUTTON = 0x00000009
	BS_PUSHBOX = 0x0000000A
	BS_OWNERDRAW = 0x0000000B
	BS_TYPEMASK = 0x0000000F
	BS_LEFTTEXT = 0x00000020
	BS_TEXT = 0x00000000
	BS_ICON = 0x00000040
	BS_BITMAP = 0x00000080
	BS_LEFT = 0x00000100
	BS_RIGHT = 0x00000200
	BS_CENTER = 0x00000300
	BS_TOP = 0x00000400
	BS_BOTTOM = 0x00000800
	BS_VCENTER = 0x00000C00
	BS_PUSHLIKE = 0x00001000
	BS_MULTILINE = 0x00002000
	BS_NOTIFY = 0x00004000
	BS_FLAT = 0x00008000
	BS_RIGHTBUTTON = BS_LEFTTEXT
	// from commctrl.h
//	BS_SPLITBUTTON = 0x0000000C		// Windows Vista and newer and(/or?) comctl6 only
//	BS_DEFSPLITBUTTON = 0x0000000D	// Windows Vista and newer and(/or?) comctl6 only
//	BS_COMMANDLINK = 0x0000000E		// Windows Vista and newer and(/or?) comctl6 only
//	BS_DEFCOMMANDLINK = 0x0000000F	// Windows Vista and newer and(/or?) comctl6 only
)

// Button WM_COMMAND notifications.
const (
	// from winuser.h
	BN_CLICKED = 0
	BN_PAINT = 1
	BN_HILITE = 2
	BN_UNHILITE = 3
	BN_DISABLE = 4
	BN_DOUBLECLICKED = 5
	BN_PUSHED = BN_HILITE
	BN_UNPUSHED = BN_UNHILITE
	BN_DBLCLK = BN_DOUBLECLICKED
	BN_SETFOCUS = 6
	BN_KILLFOCUS = 7
)

// Button check states.
const (
	// from winuser.h
	BST_UNCHECKED = 0x0000
	BST_CHECKED = 0x0001
	BST_INDETERMINATE = 0x0002
)

var (
	checkDlgButton = user32.NewProc("CheckDlgButton")
	checkRadioButton = user32.NewProc("CheckRadioButton")
	isDlgButtonChecked = user32.NewProc("IsDlgButtonChecked")
)

func CheckDlgButton(hDlg HWND, nIDButton int, uCheck uint32) (err error) {
	r1, _, err := checkDlgButton.Call(
		uintptr(hDlg),
		uintptr(nIDButton),
		uintptr(uCheck))
	if r1 == 0 {		// failure
		return err
	}
	return nil
}

func CheckRadioButton(hDlg HWND, nIDFirstButton int, nIDLastButton int, nIDCheckButton int) (err error) {
	r1, _, err := checkRadioButton.Call(
		uintptr(hDlg),
		uintptr(nIDFirstButton),
		uintptr(nIDLastButton),
		uintptr(nIDCheckButton))
	if r1 == 0 {		// failure
		return err
	}
	return nil
}

// TODO handle errors
func IsDlgButtonChecked(hDlg HWND, nIDButton int) (state uint32, err error) {
	r1, _, _ := isDlgButtonChecked.Call(
		uintptr(hDlg),
		uintptr(nIDButton))
	return uint32(r1), nil
}