Added edit controls and added one to the example window.

This commit is contained in:
Pietro Gagliardi 2014-02-10 15:23:09 -05:00
parent e9f25362be
commit 0808c696f8
3 changed files with 123 additions and 9 deletions

View File

@ -67,6 +67,7 @@ const (
)
// Combobox WM_COMMAND notificaitons.
// TODO filter out notifications not provided in windows 2000
const (
// from winuser.h
CBN_ERRSPACE = (-1) // TODO this will blow up the Go compiler if it's used

94
edits.go Normal file
View File

@ -0,0 +1,94 @@
// 10 february 2014
package main
import (
// "syscall"
// "unsafe"
)
// Edit control styles.
const (
// from winuser.h
ES_LEFT = 0x0000
ES_CENTER = 0x0001
ES_RIGHT = 0x0002
ES_MULTILINE = 0x0004
ES_UPPERCASE = 0x0008
ES_LOWERCASE = 0x0010
ES_PASSWORD = 0x0020
ES_AUTOVSCROLL = 0x0040
ES_AUTOHSCROLL = 0x0080
ES_NOHIDESEL = 0x0100
ES_OEMCONVERT = 0x0400
ES_READONLY = 0x0800
ES_WANTRETURN = 0x1000
ES_NUMBER = 0x2000
)
// Edit control messages.
// TODO filter out messages not provided in windows 2000
const (
// from winuser.h
EM_GETSEL = 0x00B0
EM_SETSEL = 0x00B1
EM_GETRECT = 0x00B2
EM_SETRECT = 0x00B3
EM_SETRECTNP = 0x00B4
EM_SCROLL = 0x00B5
EM_LINESCROLL = 0x00B6
EM_SCROLLCARET = 0x00B7
EM_GETMODIFY = 0x00B8
EM_SETMODIFY = 0x00B9
EM_GETLINECOUNT = 0x00BA
EM_LINEINDEX = 0x00BB
EM_SETHANDLE = 0x00BC
EM_GETHANDLE = 0x00BD
EM_GETTHUMB = 0x00BE
EM_LINELENGTH = 0x00C1
EM_REPLACESEL = 0x00C2
EM_GETLINE = 0x00C4
EM_LIMITTEXT = 0x00C5
EM_CANUNDO = 0x00C6
EM_UNDO = 0x00C7
EM_FMTLINES = 0x00C8
EM_LINEFROMCHAR = 0x00C9
EM_SETTABSTOPS = 0x00CB
EM_SETPASSWORDCHAR = 0x00CC
EM_EMPTYUNDOBUFFER = 0x00CD
EM_GETFIRSTVISIBLELINE = 0x00CE
EM_SETREADONLY = 0x00CF
EM_SETWORDBREAKPROC = 0x00D0
EM_GETWORDBREAKPROC = 0x00D1
EM_GETPASSWORDCHAR = 0x00D2
EM_SETMARGINS = 0x00D3
EM_GETMARGINS = 0x00D4
EM_SETLIMITTEXT = EM_LIMITTEXT // [;win40 Name change]
EM_GETLIMITTEXT = 0x00D5
EM_POSFROMCHAR = 0x00D6
EM_CHARFROMPOS = 0x00D7
EM_SETIMESTATUS = 0x00D8
EM_GETIMESTATUS = 0x00D9
)
// Edit control WM_COMMAND notifications.
// TODO filter out notifications not provided in windows 2000
const (
// from winuser.h
EN_SETFOCUS = 0x0100
EN_KILLFOCUS = 0x0200
EN_CHANGE = 0x0300
EN_UPDATE = 0x0400
EN_ERRSPACE = 0x0500
EN_MAXTEXT = 0x0501
EN_HSCROLL = 0x0601
EN_VSCROLL = 0x0602
EN_ALIGN_LTR_EC = 0x0700
EN_ALIGN_RTL_EC = 0x0701
EC_LEFTMARGIN = 0x0001
EC_RIGHTMARGIN = 0x0002
EC_USEFONTINFO = 0xFFFF
EMSIS_COMPOSITIONSTRING = 0x0001
EIMES_GETCOMPSTRATONCE = 0x0001
EIMES_CANCELCOMPSTRINFOCUS = 0x0002
EIMES_COMPLETECOMPSTRKILLFOCUS = 0x0004
)

37
main.go
View File

@ -20,12 +20,13 @@ func fatalf(format string, args ...interface{}) {
}
const (
IDC_BUTTON = 100
IDC_VARCOMBO = 101
IDC_FIXCOMBO = 102
IDC_BUTTON = 100 + iota
IDC_VARCOMBO
IDC_FIXCOMBO
IDC_EDIT
)
var varCombo, fixCombo HWND
var varCombo, fixCombo, edit HWND
func wndProc(hwnd HWND, msg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
switch msg {
@ -54,12 +55,18 @@ func wndProc(hwnd HWND, msg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
}
// TODO get text from index
editText, err := getText(edit)
if err != nil {
fatalf("error getting edit field text: %v", err)
}
MessageBox(hwnd,
fmt.Sprintf("button state: %s\n" +
"variable combo box text: %s\n" +
"fixed combo box text with WM_GETTEXT: %s\n" +
"fixed combo box current index: %d\n",
buttonclick, varText, fixTextWM, fixTextIndex),
"fixed combo box current index: %d\n" +
"edit field text: %s\n",
buttonclick, varText, fixTextWM, fixTextIndex, editText),
"note",
MB_OK)
}
@ -129,10 +136,12 @@ func main() {
fatalf("error creating window: %v", err)
}
const controlStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP
_, err = CreateWindowEx(
0,
"BUTTON", "Click Me",
BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
BS_PUSHBUTTON | controlStyle,
20, 20, 100, 20,
hwnd, HMENU(IDC_BUTTON), hInstance, NULL)
if err != nil {
@ -142,7 +151,7 @@ func main() {
varCombo, err = CreateWindowEx(
0,
"COMBOBOX", "",
CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
CBS_DROPDOWN | CBS_AUTOHSCROLL | controlStyle,
140, 20, 100, 20,
hwnd, HMENU(IDC_VARCOMBO), hInstance, NULL)
if err != nil {
@ -160,7 +169,7 @@ func main() {
fixCombo, err = CreateWindowEx(
0,
"COMBOBOX", "",
CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
CBS_DROPDOWNLIST | controlStyle,
140, 50, 100, 20,
hwnd, HMENU(IDC_FIXCOMBO), hInstance, NULL)
if err != nil {
@ -175,6 +184,16 @@ func main() {
}
}
edit, err = CreateWindowEx(
0,
"EDIT", "",
ES_AUTOHSCROLL | ES_NOHIDESEL | WS_BORDER | controlStyle,
20, 50, 100, 20,
hwnd, HMENU(IDC_EDIT), hInstance, NULL)
if err != nil {
fatalf("error creating edit field: %v", err)
}
_, err = ShowWindow(hwnd, nCmdShow)
if err != nil {
fatalf("error showing window: %v", err)