Example #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,
		)
	}
}
Example #2
0
func (wi *windowInternal) switchToFullscreen(monitor *Monitor, mode VideoMode) error {
	devMode := C.DEVMODEW{
		dmSize:       C.DEVMODEW_size,
		dmPelsWidth:  C.DWORD(mode.Width),
		dmPelsHeight: C.DWORD(mode.Height),
		dmBitsPerPel: C.DWORD(mode.BitsPerPixel),
		dmFields:     C.DM_PELSWIDTH | C.DM_PELSHEIGHT | C.DM_BITSPERPEL,
	}

	// Apply fullscreen mode
	if err := ChangeDisplaySettingsExW(&monitor.internal.info.szDevice[0], &devMode, nil, C.CDS_FULLSCREEN, nil); err != nil {
		return err
	}

	// Make the window flags compatible with fullscreen mode
	C.SetWindowULong(wi.window.Handle, C.GWL_STYLE, C.WS_POPUP|C.WS_CLIPCHILDREN|C.WS_CLIPSIBLINGS)
	C.SetWindowLong(wi.window.Handle, C.GWL_EXSTYLE, C.WS_EX_APPWINDOW)

	// Resize the window so that it fits the entire screen
	C.SetWindowPos(wi.window.Handle, HWND_TOP, 0, 0, C.int(mode.Width), C.int(mode.Height), C.SWP_FRAMECHANGED)
	C.ShowWindow(wi.window.Handle, C.SW_SHOW)

	// Set this as the current fullscreen window
	wi.monitor = monitor
	wi.devMode = &devMode

	return nil
}
Example #3
0
// 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)
}
Example #4
0
// Change the position of the window on screen
//
// This function only works for top-level windows
// (i.e. it will be ignored for windows created from
// the handle of a child window/control).
func (wi *windowInternal) setPosition(x, y int) {
	C.SetWindowPos(wi.window.Handle, nil, C.int(x), C.int(y), 0, 0, C.SWP_NOSIZE|C.SWP_NOZORDER)
}