Added listboxes and added a list box to the example window.
This commit is contained in:
parent
0808c696f8
commit
4d674ebd3d
|
@ -6,7 +6,8 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO filter out commctrl.h stuff because the combobox stuff has values that differ between windows versions and bleh
|
// TODO filter out commctrl.h stuff because the combobox and listbox stuff has values that differ between windows versions and bleh
|
||||||
|
// either that or switch to ComboBoxEx and ListView because they might not have that problem???
|
||||||
|
|
||||||
var (
|
var (
|
||||||
user32 = syscall.NewLazyDLL("user32.dll")
|
user32 = syscall.NewLazyDLL("user32.dll")
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
// 10 february 2014
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
// "syscall"
|
||||||
|
// "unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Listbox styles.
|
||||||
|
const (
|
||||||
|
// from winuser.h
|
||||||
|
LBS_NOTIFY = 0x0001
|
||||||
|
LBS_SORT = 0x0002
|
||||||
|
LBS_NOREDRAW = 0x0004
|
||||||
|
LBS_MULTIPLESEL = 0x0008
|
||||||
|
LBS_OWNERDRAWFIXED = 0x0010
|
||||||
|
LBS_OWNERDRAWVARIABLE = 0x0020
|
||||||
|
LBS_HASSTRINGS = 0x0040
|
||||||
|
LBS_USETABSTOPS = 0x0080
|
||||||
|
LBS_NOINTEGRALHEIGHT = 0x0100
|
||||||
|
LBS_MULTICOLUMN = 0x0200
|
||||||
|
LBS_WANTKEYBOARDINPUT = 0x0400
|
||||||
|
LBS_EXTENDEDSEL = 0x0800
|
||||||
|
LBS_DISABLENOSCROLL = 0x1000
|
||||||
|
LBS_NODATA = 0x2000
|
||||||
|
LBS_NOSEL = 0x4000
|
||||||
|
LBS_COMBOBOX = 0x8000
|
||||||
|
LBS_STANDARD = (LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Listbox messages.
|
||||||
|
// TODO filter out messages not provided in windows 2000
|
||||||
|
const (
|
||||||
|
// from winuser.h
|
||||||
|
LB_ADDSTRING = 0x0180
|
||||||
|
LB_INSERTSTRING = 0x0181
|
||||||
|
LB_DELETESTRING = 0x0182
|
||||||
|
LB_SELITEMRANGEEX = 0x0183
|
||||||
|
LB_RESETCONTENT = 0x0184
|
||||||
|
LB_SETSEL = 0x0185
|
||||||
|
LB_SETCURSEL = 0x0186
|
||||||
|
LB_GETSEL = 0x0187
|
||||||
|
LB_GETCURSEL = 0x0188
|
||||||
|
LB_GETTEXT = 0x0189
|
||||||
|
LB_GETTEXTLEN = 0x018A
|
||||||
|
LB_GETCOUNT = 0x018B
|
||||||
|
LB_SELECTSTRING = 0x018C
|
||||||
|
LB_DIR = 0x018D
|
||||||
|
LB_GETTOPINDEX = 0x018E
|
||||||
|
LB_FINDSTRING = 0x018F
|
||||||
|
LB_GETSELCOUNT = 0x0190
|
||||||
|
LB_GETSELITEMS = 0x0191
|
||||||
|
LB_SETTABSTOPS = 0x0192
|
||||||
|
LB_GETHORIZONTALEXTENT = 0x0193
|
||||||
|
LB_SETHORIZONTALEXTENT = 0x0194
|
||||||
|
LB_SETCOLUMNWIDTH = 0x0195
|
||||||
|
LB_ADDFILE = 0x0196
|
||||||
|
LB_SETTOPINDEX = 0x0197
|
||||||
|
LB_GETITEMRECT = 0x0198
|
||||||
|
LB_GETITEMDATA = 0x0199
|
||||||
|
LB_SETITEMDATA = 0x019A
|
||||||
|
LB_SELITEMRANGE = 0x019B
|
||||||
|
LB_SETANCHORINDEX = 0x019C
|
||||||
|
LB_GETANCHORINDEX = 0x019D
|
||||||
|
LB_SETCARETINDEX = 0x019E
|
||||||
|
LB_GETCARETINDEX = 0x019F
|
||||||
|
LB_SETITEMHEIGHT = 0x01A0
|
||||||
|
LB_GETITEMHEIGHT = 0x01A1
|
||||||
|
LB_FINDSTRINGEXACT = 0x01A2
|
||||||
|
LB_SETLOCALE = 0x01A5
|
||||||
|
LB_GETLOCALE = 0x01A6
|
||||||
|
LB_SETCOUNT = 0x01A7
|
||||||
|
LB_INITSTORAGE = 0x01A8
|
||||||
|
LB_ITEMFROMPOINT = 0x01A9
|
||||||
|
LB_MULTIPLEADDSTRING = 0x01B1
|
||||||
|
LB_GETLISTBOXINFO = 0x01B2
|
||||||
|
)
|
||||||
|
|
||||||
|
// Listbox WM_COMMAND notifications and message returns.
|
||||||
|
// TODO filter out notifications not provided in windows 2000
|
||||||
|
const (
|
||||||
|
// from winuser.h
|
||||||
|
LB_OKAY = 0
|
||||||
|
LB_ERR = (-1) // TODO this will blow up the Go compiler if it's used
|
||||||
|
LBN_ERRSPACE = (-2) // TODO this will blow up the Go compiler if it's used
|
||||||
|
LBN_SELCHANGE = 1
|
||||||
|
LBN_DBLCLK = 2
|
||||||
|
LBN_SELCANCEL = 3
|
||||||
|
LBN_SETFOCUS = 4
|
||||||
|
LBN_KILLFOCUS = 5
|
||||||
|
)
|
33
main.go
33
main.go
|
@ -24,9 +24,10 @@ const (
|
||||||
IDC_VARCOMBO
|
IDC_VARCOMBO
|
||||||
IDC_FIXCOMBO
|
IDC_FIXCOMBO
|
||||||
IDC_EDIT
|
IDC_EDIT
|
||||||
|
IDC_LIST
|
||||||
)
|
)
|
||||||
|
|
||||||
var varCombo, fixCombo, edit HWND
|
var varCombo, fixCombo, edit, list HWND
|
||||||
|
|
||||||
func wndProc(hwnd HWND, msg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
|
func wndProc(hwnd HWND, msg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
|
||||||
switch msg {
|
switch msg {
|
||||||
|
@ -60,13 +61,20 @@ func wndProc(hwnd HWND, msg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
|
||||||
fatalf("error getting edit field text: %v", err)
|
fatalf("error getting edit field text: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listIndex, err := SendMessage(list, LB_GETCURSEL, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
fatalf("error getting fixed list box current selection: %v", err)
|
||||||
|
}
|
||||||
|
// TODO get text from index
|
||||||
|
|
||||||
MessageBox(hwnd,
|
MessageBox(hwnd,
|
||||||
fmt.Sprintf("button state: %s\n" +
|
fmt.Sprintf("button state: %s\n" +
|
||||||
"variable combo box text: %s\n" +
|
"variable combo box text: %s\n" +
|
||||||
"fixed combo box text with WM_GETTEXT: %s\n" +
|
"fixed combo box text with WM_GETTEXT: %s\n" +
|
||||||
"fixed combo box current index: %d\n" +
|
"fixed combo box current index: %d\n" +
|
||||||
"edit field text: %s\n",
|
"edit field text: %s\n" +
|
||||||
buttonclick, varText, fixTextWM, fixTextIndex, editText),
|
"list box current index: %d\n",
|
||||||
|
buttonclick, varText, fixTextWM, fixTextIndex, editText, listIndex),
|
||||||
"note",
|
"note",
|
||||||
MB_OK)
|
MB_OK)
|
||||||
}
|
}
|
||||||
|
@ -194,6 +202,25 @@ func main() {
|
||||||
fatalf("error creating edit field: %v", err)
|
fatalf("error creating edit field: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list, err = CreateWindowEx(
|
||||||
|
0,
|
||||||
|
"LISTBOX", "",
|
||||||
|
LBS_STANDARD | controlStyle,
|
||||||
|
20, 80, 100, 100,
|
||||||
|
hwnd, HMENU(IDC_FIXCOMBO), hInstance, NULL)
|
||||||
|
if err != nil {
|
||||||
|
fatalf("error creating list box: %v", err)
|
||||||
|
}
|
||||||
|
lItems := []string{"i", "j", "k", "l"}
|
||||||
|
for _, v := range lItems {
|
||||||
|
_, err := SendMessage(list, LB_ADDSTRING, 0,
|
||||||
|
LPARAMFromString(v))
|
||||||
|
if err != nil {
|
||||||
|
fatalf("error adding %q to list box: %v", v, err)
|
||||||
|
}
|
||||||
|
// TODO check actual return value as THAT indicates an error
|
||||||
|
}
|
||||||
|
|
||||||
_, err = ShowWindow(hwnd, nCmdShow)
|
_, err = ShowWindow(hwnd, nCmdShow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalf("error showing window: %v", err)
|
fatalf("error showing window: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue