Merge pull request #17 from papplampe/master

added Center function to window + Windows implementation (thanks to @papplampe)
This commit is contained in:
Pietro Gagliardi 2014-06-11 09:42:11 -04:00
commit 2407a415b9
5 changed files with 28 additions and 0 deletions

View File

@ -91,6 +91,7 @@ var (
_setWindowPos = user32.NewProc("SetWindowPos")
_setWindowText = user32.NewProc("SetWindowTextW")
_showWindow = user32.NewProc("ShowWindow")
_getWindowRect = user32.NewProc("GetWindowRect")
)
type _MINMAXINFO struct {

View File

@ -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)
}

View File

@ -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()
}

View File

@ -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

View File

@ -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