GENERATE_INTERCEPT_HEADER(SetWindowLongA, LONG, WINAPI, _In_ HWND hWnd, _In_ int nIndex, _In_ LONG dwNewLong) { SDLOG(2, "DetouredSetWindowLongA hwnd: %p -- index: %s -- value: %d\n", hWnd, WindowLongOffsetToString(nIndex), dwNewLong); LONG ret = TrueSetWindowLongA(hWnd, nIndex, dwNewLong); if(nIndex == GWL_WNDPROC && Settings::get().getInterceptWindowProc()) { prevWndProcs[hWnd] = (WNDPROC)dwNewLong; TrueSetWindowLongA(hWnd, GWL_WNDPROC, (LONG)&InterceptWindowProc); } return ret; }
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); } }