summaryrefslogtreecommitdiff
path: root/stdwndclass_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-05 23:27:17 -0400
committerPietro Gagliardi <[email protected]>2014-06-05 23:27:17 -0400
commit00ec85dee69130ac4294e71be45470324244324c (patch)
tree550606bc7559a4a9d65389618027d488f08bcf8f /stdwndclass_windows.go
parentbb44712fad85ad7262ab6b82b3056753e4f1f20e (diff)
Implemented code to save and restore control focus on Windows properly when switching away from/back to our program. It's disabled for now though because it doesn't seem to work...
Diffstat (limited to 'stdwndclass_windows.go')
-rw-r--r--stdwndclass_windows.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go
index 7ec25fb..d32bd8c 100644
--- a/stdwndclass_windows.go
+++ b/stdwndclass_windows.go
@@ -68,6 +68,43 @@ func storeSysData(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRES
return defWindowProc(hwnd, uMsg, wParam, lParam)
}
+var (
+ _getFocus = user32.NewProc("GetFocus")
+ _isChild = user32.NewProc("IsChild")
+ // _setFocus in area_windows.go
+)
+
+// this is needed to ensure focus is preserved when switching away from and back to our program
+// from http://blogs.msdn.com/b/oldnewthing/archive/2014/05/21/10527168.aspx
+func (s *sysData) handleFocus(wParam _WPARAM) {
+ // parameter splitting from Microsoft's windowsx.h
+ state := uint32(wParam.LOWORD()) // originally UINT
+ minimized := wParam.HIWORD() != 0
+
+ if minimized { // don't do anything on minimize
+ return
+ }
+ if state == _WA_INACTIVE { // focusing out
+ old, _, _ := _getFocus.Call()
+ if _HWND(old) != _HWND(_NULL) { // if there is one
+ r1, _, _ := _isChild.Call(
+ uintptr(s.hwnd),
+ old)
+ if r1 != 0 {
+ s.lastfocus = _HWND(old)
+println("s",s.lastfocus)
+ }
+ }
+ } else { // focusing in
+ if s.lastfocus != _HWND(_NULL) { // if we have one
+ r1, _, err := _setFocus.Call(uintptr(s.lastfocus))
+ if _HWND(r1) == _HWND(_NULL) {
+ panic(fmt.Errorf("error setting focus to previously focused window on reactivating Window: %v", err))
+ }
+ }
+ }
+}
+
func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
s := getSysData(hwnd)
if s == nil { // not yet saved
@@ -105,6 +142,9 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
}
}
return 0
+// case _WM_ACTIVATE:
+// s.handleFocus(wParam)
+// return 0
case _WM_GETMINMAXINFO:
mm := lParam.MINMAXINFO()
// ... minimum size