diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-11 09:42:11 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-11 09:42:11 -0400 |
| commit | 2407a415b955b514f086d5441e11c41b6dd41e1d (patch) | |
| tree | 7d35fc8183616b75b65a89b006be043b173b171b | |
| parent | 5fa1bd22e2d457523949e0e5e1dece729d053129 (diff) | |
| parent | 4fa35b22391d56ba22725229f8d99f0061c910d0 (diff) | |
Merge pull request #17 from papplampe/master
added Center function to window + Windows implementation (thanks to @papplampe)
| -rw-r--r-- | common_windows.go | 1 | ||||
| -rw-r--r-- | sysdata_windows.go | 12 | ||||
| -rw-r--r-- | window.go | 11 | ||||
| -rw-r--r-- | zconstants_windows_386.go | 2 | ||||
| -rw-r--r-- | zconstants_windows_amd64.go | 2 |
5 files changed, 28 insertions, 0 deletions
diff --git a/common_windows.go b/common_windows.go index 8324e2e..2b3c5c8 100644 --- a/common_windows.go +++ b/common_windows.go @@ -91,6 +91,7 @@ var ( _setWindowPos = user32.NewProc("SetWindowPos") _setWindowText = user32.NewProc("SetWindowTextW") _showWindow = user32.NewProc("ShowWindow") + _getWindowRect = user32.NewProc("GetWindowRect") ) type _MINMAXINFO struct { diff --git a/sysdata_windows.go b/sysdata_windows.go index 4a4f69f..76c068c 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -685,3 +685,15 @@ func (s *sysData) repaintAll() { } <-ret } + +func (s *sysData) center() { + var ws _RECT + _getWindowRect.Call(uintptr(s.hwnd), uintptr(unsafe.Pointer(&ws))) + dw, _, _ := _getSystemMetrics.Call(_SM_CXFULLSCREEN) + dh, _, _ := _getSystemMetrics.Call(_SM_CYFULLSCREEN) + ww := ws.right - ws.left + wh := ws.bottom - ws.top + wx := (int32(dw) / 2) - (ww / 2) + wy := (int32(dh) / 2) - (wh / 2) + s.setRect(int(wx), int(wy), int(ww), int(wh), 0) +} @@ -120,3 +120,14 @@ func (w *Window) Hide() { w.sysData.hide() } + +// Centers the window +func (w *Window) Center() { + w.lock.Lock() + defer w.lock.Unlock() + + if !w.created { + return + } + w.sysData.center() +} diff --git a/zconstants_windows_386.go b/zconstants_windows_386.go index 0dfbf22..1db9e22 100644 --- a/zconstants_windows_386.go +++ b/zconstants_windows_386.go @@ -81,6 +81,8 @@ const _SIF_RANGE = 1 const _SIF_TRACKPOS = 16 const _SM_CXDOUBLECLK = 36 const _SM_CYDOUBLECLK = 37 +const _SM_CXFULLSCREEN = 16 +const _SM_CYFULLSCREEN = 17 const _SPI_GETNONCLIENTMETRICS = 41 const _SRCCOPY = 13369376 const _SS_LEFTNOWORDWRAP = 12 diff --git a/zconstants_windows_amd64.go b/zconstants_windows_amd64.go index de3a31e..a8bed71 100644 --- a/zconstants_windows_amd64.go +++ b/zconstants_windows_amd64.go @@ -81,6 +81,8 @@ const _SIF_RANGE = 1 const _SIF_TRACKPOS = 16 const _SM_CXDOUBLECLK = 36 const _SM_CYDOUBLECLK = 37 +const _SM_CXFULLSCREEN = 16 +const _SM_CYFULLSCREEN = 17 const _SPI_GETNONCLIENTMETRICS = 41 const _SRCCOPY = 13369376 const _SS_LEFTNOWORDWRAP = 12 |
