From bb44712fad85ad7262ab6b82b3056753e4f1f20e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 5 Jun 2014 18:28:40 -0400 Subject: [PATCH] Changed Checkbox on Windows to use BS_CHECKBOX instead of BS_AUTOCHECKBOX; this will be necessary to fix the focus issue in todo.md (see http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx). --- stdwndclass_windows.go | 19 +++++++++++++++++++ sysdata_windows.go | 3 ++- zconstants_windows_386.go | 4 +++- zconstants_windows_amd64.go | 4 +++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go index f4004e4..7ec25fb 100644 --- a/stdwndclass_windows.go +++ b/stdwndclass_windows.go @@ -84,6 +84,25 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL if wParam.HIWORD() == _BN_CLICKED { ss.signal() } + case c_checkbox: + // we opt into doing this ourselves because http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx + if wParam.HIWORD() == _BN_CLICKED { + state, _, _ := _sendMessage.Call( + uintptr(ss.hwnd), + uintptr(_BM_GETCHECK), + uintptr(0), + uintptr(0)) + if state == _BST_CHECKED { + state = _BST_UNCHECKED + } else if state == _BST_UNCHECKED { + state = _BST_CHECKED + } + _sendMessage.Call( + uintptr(ss.hwnd), + uintptr(_BM_SETCHECK), + state, // already uintptr + uintptr(0)) + } } return 0 case _WM_GETMINMAXINFO: diff --git a/sysdata_windows.go b/sysdata_windows.go index d41fe58..16d625a 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -57,7 +57,8 @@ var classTypes = [nctypes]*classData{ }, c_checkbox: &classData{ name: toUTF16("BUTTON"), - style: _BS_AUTOCHECKBOX | controlstyle, + // don't use BS_AUTOCHECKBOX because http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx + style: _BS_CHECKBOX | controlstyle, xstyle: 0 | controlxstyle, }, c_combobox: &classData{ diff --git a/zconstants_windows_386.go b/zconstants_windows_386.go index 6e06392..254e6fd 100644 --- a/zconstants_windows_386.go +++ b/zconstants_windows_386.go @@ -6,9 +6,11 @@ const _AC_SRC_OVER = 0 const _BCM_GETIDEALSIZE = 5633 const _BI_RGB = 0 const _BM_GETCHECK = 240 +const _BM_SETCHECK = 241 const _BN_CLICKED = 0 const _BST_CHECKED = 1 -const _BS_AUTOCHECKBOX = 3 +const _BST_UNCHECKED = 0 +const _BS_CHECKBOX = 2 const _BS_PUSHBUTTON = 0 const _CBS_AUTOHSCROLL = 64 const _CBS_DROPDOWN = 2 diff --git a/zconstants_windows_amd64.go b/zconstants_windows_amd64.go index 9bcb36d..ec746c7 100644 --- a/zconstants_windows_amd64.go +++ b/zconstants_windows_amd64.go @@ -6,9 +6,11 @@ const _AC_SRC_OVER = 0 const _BCM_GETIDEALSIZE = 5633 const _BI_RGB = 0 const _BM_GETCHECK = 240 +const _BM_SETCHECK = 241 const _BN_CLICKED = 0 const _BST_CHECKED = 1 -const _BS_AUTOCHECKBOX = 3 +const _BST_UNCHECKED = 0 +const _BS_CHECKBOX = 2 const _BS_PUSHBUTTON = 0 const _CBS_AUTOHSCROLL = 64 const _CBS_DROPDOWN = 2