Added window sizing. I think I'm now ready for the wrapper itself.
This commit is contained in:
parent
6ae39f57a2
commit
271c89bad5
22
main.go
22
main.go
|
@ -92,6 +92,11 @@ func wndProc(hwnd HWND, msg uint32, wParam WPARAM, lParam LPARAM) LRESULT {
|
|||
mm.PtMinTrackSize.X = 320
|
||||
mm.PtMinTrackSize.Y = 240
|
||||
return 0
|
||||
case WM_SIZE:
|
||||
if wParam != SIZE_MINIMIZED {
|
||||
resize(hwnd)
|
||||
}
|
||||
return 0
|
||||
case WM_CLOSE:
|
||||
err := DestroyWindow(hwnd)
|
||||
if err != nil {
|
||||
|
@ -119,6 +124,22 @@ func setFontAll(hwnd HWND, lParam LPARAM) (cont bool) {
|
|||
return true
|
||||
}
|
||||
|
||||
func resize(hwnd HWND) {
|
||||
cr, err := GetClientRect(hwnd)
|
||||
if err != nil {
|
||||
fatalf("error getting window client rect: %v", err)
|
||||
}
|
||||
cr.Bottom -= 80 // Y position of listbox
|
||||
cr.Bottom -= 20 // amount of pixels to leave behind
|
||||
err = SetWindowPos(list,
|
||||
HWND_TOP,
|
||||
20, 80, 100, int(cr.Bottom),
|
||||
0)
|
||||
if err != nil {
|
||||
fatalf("error resizing listbox: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
const className = "mainwin"
|
||||
|
||||
func main() {
|
||||
|
@ -271,6 +292,7 @@ func main() {
|
|||
if err != nil {
|
||||
fatalf("error setting font on controls: %v", err)
|
||||
}
|
||||
resize(hwnd)
|
||||
|
||||
_, err = ShowWindow(hwnd, nCmdShow)
|
||||
if err != nil {
|
||||
|
|
|
@ -12,3 +12,10 @@ type POINT struct {
|
|||
X int32
|
||||
Y int32
|
||||
}
|
||||
|
||||
type RECT struct {
|
||||
Left int32
|
||||
Top int32
|
||||
Right int32
|
||||
Bottom int32
|
||||
}
|
||||
|
|
62
windows.go
62
windows.go
|
@ -114,6 +114,39 @@ const (
|
|||
COLOR_WINDOWTEXT = 8
|
||||
)
|
||||
|
||||
// SetWindowPos hWndInsertAfter values.
|
||||
const (
|
||||
HWND_BOTTOM = HWND(1)
|
||||
HWND_TOP = HWND(0)
|
||||
)
|
||||
|
||||
// SetWindowPos hWndInsertAfter values that Go won't allow as constants.
|
||||
var (
|
||||
_HWND_NOTOPMOST = -2
|
||||
HWND_NOTOPMOST = HWND(_HWND_NOTOPMOST)
|
||||
_HWND_TOPMOST = -1
|
||||
HWND_TOPMOST = HWND(_HWND_TOPMOST)
|
||||
)
|
||||
|
||||
// SetWindowPos uFlags values.
|
||||
const (
|
||||
SWP_DRAWFRAME = 0x0020
|
||||
SWP_FRAMECHANGED = 0x0020
|
||||
SWP_HIDEWINDOW = 0x0080
|
||||
SWP_NOACTIVATE = 0x0010
|
||||
SWP_NOCOPYBITS = 0x0100
|
||||
SWP_NOMOVE = 0x0002
|
||||
SWP_NOOWNERZORDER = 0x0200
|
||||
SWP_NOREDRAW = 0x0008
|
||||
SWP_NOREPOSITION = 0x0200
|
||||
SWP_NOSENDCHANGING = 0x0400
|
||||
SWP_NOSIZE = 0x0001
|
||||
SWP_NOZORDER = 0x0004
|
||||
SWP_SHOWWINDOW = 0x0040
|
||||
SWP_ASYNCWINDOWPOS = 0x4000
|
||||
SWP_DEFERERASE = 0x2000
|
||||
)
|
||||
|
||||
// ShowWindow settings.
|
||||
const (
|
||||
SW_FORCEMINIMIZE = 11
|
||||
|
@ -134,7 +167,9 @@ const (
|
|||
var (
|
||||
createWindowEx = user32.NewProc("CreateWindowExW")
|
||||
destroyWindow = user32.NewProc("DestroyWindow")
|
||||
getClientRect = user32.NewProc("GetClientRect")
|
||||
enumChildWindows = user32.NewProc("EnumChildWindows")
|
||||
setWindowPos = user32.NewProc("SetWindowPos")
|
||||
showWindow = user32.NewProc("ShowWindow")
|
||||
)
|
||||
|
||||
|
@ -188,6 +223,33 @@ func EnumChildWindows(hWndParent HWND, lpEnumFunc WNDENUMPROC, lParam LPARAM) (e
|
|||
return nil
|
||||
}
|
||||
|
||||
// TODO return the rect itself?
|
||||
func GetClientRect(hWnd HWND) (lpRect *RECT, err error) {
|
||||
lpRect = new(RECT)
|
||||
r1, _, err := getClientRect.Call(
|
||||
uintptr(hWnd),
|
||||
uintptr(unsafe.Pointer(lpRect)))
|
||||
if r1 == 0 { // failure
|
||||
return nil, err
|
||||
}
|
||||
return lpRect, nil
|
||||
}
|
||||
|
||||
func SetWindowPos(hWnd HWND, hWndInsertAfter HWND, X int, Y int, cx int, cy int, uFlags uint32) (err error) {
|
||||
r1, _, err := setWindowPos.Call(
|
||||
uintptr(hWnd),
|
||||
uintptr(hWndInsertAfter),
|
||||
uintptr(X),
|
||||
uintptr(Y),
|
||||
uintptr(cx),
|
||||
uintptr(cy),
|
||||
uintptr(uFlags))
|
||||
if r1 == 0 { // failure
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO figure out how to handle errors
|
||||
func ShowWindow(hWnd HWND, nCmdShow int) (previouslyVisible bool, err error) {
|
||||
r1, _, _ := showWindow.Call(
|
||||
|
|
Loading…
Reference in New Issue