Cranch

Untitled

Nov 17th, 2025
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. if (isMenuActive != lastIsMenuActive)
  2.         {
  3.             if (isMenuActive)
  4.             {
  5.                 /* Remove TRANSPARENT and NOACTIVATE. */
  6.                 LONG ex = GetWindowLong(hwnd, GWL_EXSTYLE);
  7.                 ex &= ~WS_EX_TRANSPARENT;
  8.                 ex &= ~WS_EX_NOACTIVATE;
  9.                 ex |= (WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
  10.                 SetWindowLong(hwnd, GWL_EXSTYLE, ex);
  11.                 SetWindowPos
  12.                 (
  13.                     hwnd, nullptr, 0, 0, 0, 0,
  14.                     SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED
  15.                 );
  16.  
  17.                 /* Activate the overlay so the game stops receiving input. */
  18.                 DWORD gameTid = GetWindowThreadProcessId(hTargetWindow, nullptr);
  19.                 DWORD myTid = GetCurrentThreadId();
  20.                 AttachThreadInput(myTid, gameTid, TRUE);
  21.                 SetForegroundWindow(hwnd);
  22.                 SetActiveWindow(hwnd);
  23.                 SetFocus(hwnd);
  24.                 AttachThreadInput(myTid, gameTid, FALSE);
  25.  
  26.                 /* Capture the mouse (all WM_MOUSE messages go to us). */
  27.                 if (GetCapture() != hwnd)
  28.                     SetCapture(hwnd);
  29.  
  30.                 /* If the game hides the cursor, draw the ImGui cursor. */
  31.                 ImGui::GetIO().MouseDrawCursor = true;
  32.             }
  33.             else
  34.             {
  35.                 /* Restore click-through behavior for the overlay. */
  36.                 LONG ex = GetWindowLong(hwnd, GWL_EXSTYLE);
  37.                 ex |= WS_EX_TRANSPARENT;
  38.                 ex &= ~WS_EX_NOACTIVATE; // keep without NOACTIVATE so clicking can activate
  39.                 ex |= (WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW);
  40.                 SetWindowLong(hwnd, GWL_EXSTYLE, ex);
  41.                 SetWindowPos
  42.                 (
  43.                     hwnd, nullptr, 0, 0, 0, 0,
  44.                     SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED
  45.                 );
  46.  
  47.                 if (GetCapture() == hwnd)
  48.                     ReleaseCapture();
  49.  
  50.                 ImGui::GetIO().MouseDrawCursor = false;
  51.  
  52.                 /* Return focus to the game. */
  53.                 if (IsWindow(hTargetWindow))
  54.                     SetForegroundWindow(hTargetWindow);
  55.             }
Advertisement
Add Comment
Please, Sign In to add comment