Exemple #1
0
func toggleFullscreen(window C.HWND) {
	style := C.GetWindowLong(window, C.GWL_STYLE)
	if style&C.WS_OVERLAPPEDWINDOW != 0 {
		// go into full-screen
		monitorInfo := C.MONITORINFO{cbSize: C.sizeof_MONITORINFO}
		previousPlacement.length = C.sizeof_WINDOWPLACEMENT
		monitor := C.MonitorFromWindow(window, C.MONITOR_DEFAULTTOPRIMARY)
		if C.GetWindowPlacement(window, &previousPlacement) != 0 &&
			C.GetMonitorInfo(monitor, &monitorInfo) != 0 {
			C.SetWindowLong(window, C.GWL_STYLE, style & ^C.WS_OVERLAPPEDWINDOW)
			C.SetWindowPos(window, C.HWND(unsafe.Pointer(uintptr(0))),
				C.int(monitorInfo.rcMonitor.left),
				C.int(monitorInfo.rcMonitor.top),
				C.int(monitorInfo.rcMonitor.right-monitorInfo.rcMonitor.left),
				C.int(monitorInfo.rcMonitor.bottom-monitorInfo.rcMonitor.top),
				C.SWP_NOOWNERZORDER|C.SWP_FRAMECHANGED,
			)
		}
	} else {
		// go into windowed mode
		C.SetWindowLong(window, C.GWL_STYLE, style|C.WS_OVERLAPPEDWINDOW)
		C.SetWindowPlacement(window, &previousPlacement)
		C.SetWindowPos(window, nil, 0, 0, 0, 0,
			C.SWP_NOMOVE|C.SWP_NOSIZE|C.SWP_NOZORDER|
				C.SWP_NOOWNERZORDER|C.SWP_FRAMECHANGED,
		)
	}
}
// Change the size of the rendering region of the window
func (wi *windowInternal) setSize(x, y uint) {
	// SetWindowPos wants the total size of the window (including title bar and borders),
	// so we have to compute it
	rect := C.RECT{0, 0, C.LONG(x), C.LONG(y)}
	style := C.GetWindowLong(wi.window.Handle, C.GWL_STYLE)
	C.__AdjustWindowRect(&rect, C.DWORD(style), C.FALSE)
	width := C.int(rect.right - rect.left)
	height := C.int(rect.bottom - rect.top)

	C.SetWindowPos(wi.window.Handle, nil, 0, 0, width, height, C.SWP_NOMOVE|C.SWP_NOZORDER)
}