Merge pull request #17 from papplampe/master
added Center function to window + Windows implementation (thanks to @papplampe)
This commit is contained in:
commit
2407a415b9
|
@ -91,6 +91,7 @@ var (
|
|||
_setWindowPos = user32.NewProc("SetWindowPos")
|
||||
_setWindowText = user32.NewProc("SetWindowTextW")
|
||||
_showWindow = user32.NewProc("ShowWindow")
|
||||
_getWindowRect = user32.NewProc("GetWindowRect")
|
||||
)
|
||||
|
||||
type _MINMAXINFO struct {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
11
window.go
11
window.go
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue