Esempio n. 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,
		)
	}
}
Esempio n. 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
}