diff options
| -rw-r--r-- | checkbox.go | 12 | ||||
| -rw-r--r-- | controls_windows.go | 21 | ||||
| -rw-r--r-- | main.go | 6 | ||||
| -rw-r--r-- | sysdata.go | 3 | ||||
| -rw-r--r-- | sysdata_windows.go | 18 |
5 files changed, 55 insertions, 5 deletions
diff --git a/checkbox.go b/checkbox.go index cd9a896..89768ef 100644 --- a/checkbox.go +++ b/checkbox.go @@ -39,7 +39,17 @@ func (c *Checkbox) SetText(text string) (err error) { return nil } -// TODO Checked() +// Checked() returns whether or not the checkbox has been checked. +func (c *Checkbox) Checked() bool { + c.lock.Lock() + defer c.lock.Unlock() + + check, err := c.sysData.isChecked() + if err != nil { + panic(err) // TODO + } + return check +} func (c *Checkbox) apply(window *sysData) error { c.lock.Lock() diff --git a/controls_windows.go b/controls_windows.go index 06d7317..3a6f472 100644 --- a/controls_windows.go +++ b/controls_windows.go @@ -38,10 +38,25 @@ const ( _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_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 +// _BS_DEFCOMMANDLINK = 0x0000000F // Windows Vista and newer and(/or?) comctl6 only +) + +// Button messages. +// TODO check if any are not defined on Windows 2000 +const ( + // from winuser.h + _BM_GETCHECK = 0x00F0 + _BM_SETCHECK = 0x00F1 + _BM_GETSTATE = 0x00F2 + _BM_SETSTATE = 0x00F3 + _BM_SETSTYLE = 0x00F4 + _BM_CLICK = 0x00F5 + _BM_GETIMAGE = 0x00F6 + _BM_SETIMAGE = 0x00F7 + _BM_SETDONTCLICK = 0x00F8 ) // Button WM_COMMAND notifications. @@ -1,6 +1,10 @@ // 11 february 2014 package main +import ( + "fmt" +) + func main() { w := NewWindow("Main Window", 320, 240) w.Closing = make(chan struct{}) @@ -23,7 +27,7 @@ mainloop: case <-w.Closing: break mainloop case <-b.Clicked: - err := w.SetTitle("Button Clicked") + err := w.SetTitle(fmt.Sprintf("Check State: %v", c.Checked())) if err != nil { panic(err) } @@ -26,6 +26,9 @@ func (c *cSysData) setText(text string) error { func (c *cSysData) setRect(x int, y int, width int, height int) error { panic(runtime.GOOS + " sysData does not define setRect()") } +func (c *cSysData) isChecked() (bool, error) { + panic(runtime.GOOS + " sysData does not define isChecked()") +} const ( c_window = iota diff --git a/sysdata_windows.go b/sysdata_windows.go index 6856bc1..b62d90a 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -201,3 +201,21 @@ func (s *sysData) setRect(x int, y int, width int, height int) error { } return nil } + +// TODO figure out how to handle error +func (s *sysData) isChecked() (bool, error) { + ret := make(chan uiret) + defer close(ret) + uitask <- &uimsg{ + call: _sendMessage, + p: []uintptr{ + uintptr(s.hwnd), + uintptr(_BM_GETCHECK), + uintptr(0), + uintptr(0), + }, + ret: ret, + } + r := <-ret + return r.ret == _BST_CHECKED, nil +} |
