Example #1
0
GENERATE_INTERCEPT_HEADER(GetClientRect, BOOL, WINAPI, _In_ HWND hWnd, _Out_ LPRECT lpRect) {
	SDLOG(2, "DetouredGetClientRect\n");
	HRESULT ret = TrueGetClientRect(hWnd, lpRect);
	if(RSManager::currentlyDownsampling() && Settings::get().getModifyGetClientRect()) {
		SDLOG(2, "- override from %s\n", RectToString(lpRect).c_str());
		lpRect->right = Settings::get().getRenderWidth();
		lpRect->bottom = Settings::get().getRenderHeight();
	}
	SDLOG(2, "-> %s\n", RectToString(lpRect).c_str());
	return ret;
}
void WindowManager::applyCursorCapture() {
	if(captureCursor) {
		RECT clientrect;
		HWND hwnd = ::GetActiveWindow();
		TrueGetClientRect(hwnd, &clientrect);
		::ClientToScreen(hwnd, (LPPOINT)&clientrect.left);
		::ClientToScreen(hwnd, (LPPOINT)&clientrect.right);
		::ClipCursor(&clientrect);
	} else {
		::ClipCursor(NULL);
	}
}
void WindowManager::toggleBorderlessFullscreen() {
	borderlessFullscreen = !borderlessFullscreen;
	HWND hwnd = ::GetActiveWindow();
	if(borderlessFullscreen) {
		SDLOG(1, "WindowManager::toggleBorderlessFullscreen A hwnd: %p\n", hwnd);
		// store previous rect
		TrueGetClientRect(hwnd, &prevWindowRect);
		// set styles
		LONG lStyle = TrueGetWindowLongA(hwnd, GWL_STYLE);
		prevStyle = lStyle;
		lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
		TrueSetWindowLongA(hwnd, GWL_STYLE, lStyle);
		LONG lExStyle = TrueGetWindowLongA(hwnd, GWL_EXSTYLE);
		prevExStyle = lExStyle;
		lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
		TrueSetWindowLongA(hwnd, GWL_EXSTYLE, lExStyle);
		SDLOG(1, "WindowManager::toggleBorderlessFullscreen B\n", hwnd);
		// adjust size & position
		HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
		MONITORINFO info;
		info.cbSize = sizeof(MONITORINFO);
		GetMonitorInfo(monitor, &info);
		int monitorWidth = info.rcMonitor.right - info.rcMonitor.left;
		int monitorHeight = info.rcMonitor.bottom - info.rcMonitor.top;
		::SetWindowPos(hwnd, NULL, info.rcMonitor.left, info.rcMonitor.top, monitorWidth, monitorHeight, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
		BringWindowToTop(hwnd);
		SDLOG(1, "WindowManager::toggleBorderlessFullscreen C\n", hwnd);
	} else {
		// restore previous window
		::SetWindowLong(hwnd, GWL_STYLE, prevStyle);
		::SetWindowLong(hwnd, GWL_EXSTYLE, prevExStyle);
		RECT desiredRect = prevWindowRect;
		::AdjustWindowRect(&desiredRect, prevStyle, false);
		int wWidth = desiredRect.right - desiredRect.left, wHeight = desiredRect.bottom - desiredRect.top;
		::SetWindowPos(hwnd, NULL, prevWindowRect.left, prevWindowRect.top, wWidth, wHeight, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
	}
}