Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isMenuActive != lastIsMenuActive)
- {
- if (isMenuActive)
- {
- /* Remove TRANSPARENT and NOACTIVATE. */
- LONG ex = GetWindowLong(hwnd, GWL_EXSTYLE);
- ex &= ~WS_EX_TRANSPARENT;
- ex &= ~WS_EX_NOACTIVATE;
- ex |= (WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
- SetWindowLong(hwnd, GWL_EXSTYLE, ex);
- SetWindowPos
- (
- hwnd, nullptr, 0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED
- );
- /* Activate the overlay so the game stops receiving input. */
- DWORD gameTid = GetWindowThreadProcessId(hTargetWindow, nullptr);
- DWORD myTid = GetCurrentThreadId();
- AttachThreadInput(myTid, gameTid, TRUE);
- SetForegroundWindow(hwnd);
- SetActiveWindow(hwnd);
- SetFocus(hwnd);
- AttachThreadInput(myTid, gameTid, FALSE);
- /* Capture the mouse (all WM_MOUSE messages go to us). */
- if (GetCapture() != hwnd)
- SetCapture(hwnd);
- /* If the game hides the cursor, draw the ImGui cursor. */
- ImGui::GetIO().MouseDrawCursor = true;
- }
- else
- {
- /* Restore click-through behavior for the overlay. */
- LONG ex = GetWindowLong(hwnd, GWL_EXSTYLE);
- ex |= WS_EX_TRANSPARENT;
- ex &= ~WS_EX_NOACTIVATE; // keep without NOACTIVATE so clicking can activate
- ex |= (WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
- SetWindowLong(hwnd, GWL_EXSTYLE, ex);
- SetWindowPos
- (
- hwnd, nullptr, 0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED
- );
- if (GetCapture() == hwnd)
- ReleaseCapture();
- ImGui::GetIO().MouseDrawCursor = false;
- /* Return focus to the game. */
- if (IsWindow(hTargetWindow))
- SetForegroundWindow(hTargetWindow);
- }
Advertisement
Add Comment
Please, Sign In to add comment