Support Board
Date/Time: Mon, 04 May 2026 14:48:14 +0000
Post From: Trade windows off-screen when detached
| [2026-03-13 21:06:02] |
| User719512 - Posts: 433 |
|
This can be solved with a Python script. Grok to the rescue (and can assist if you, or others) if you don't know Python. After just a few adjustments, it generated a script to enumerate and move windows to the primary screen. window_manager.py Example: window_manager.py --enumerate Handle: 1509772, Title: ESH26_FUT_CME/ESH26_FUT_CME [CV][M] #10 window_manager.py --move-window 1509772 import argparse import win32gui import win32con import win32console def enumerate_windows(include_empty_title=False): windows = [] def enum_callback(hwnd, results): if win32gui.IsWindowVisible(hwnd): title = win32gui.GetWindowText(hwnd) class_name = win32gui.GetClassName(hwnd) if include_empty_title or title: results.append((hwnd, title, class_name)) win32gui.EnumWindows(enum_callback, windows) return windows def enumerate_child_windows(parent_hwnd): children = [] def enum_child_callback(hwnd, results): if win32gui.IsWindowVisible(hwnd): title = win32gui.GetWindowText(hwnd) class_name = win32gui.GetClassName(hwnd) results.append((hwnd, title, class_name)) win32gui.EnumChildWindows(parent_hwnd, enum_child_callback, children) return children def move_window(hwnd, x=100, y=100): if not win32gui.IsWindow(hwnd): raise ValueError("Invalid window handle") if not win32gui.IsWindowVisible(hwnd): print("Warning: Window is not visible, but attempting move anyway") style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE) is_child = bool(style & win32con.WS_CHILD) # Get current size rect = win32gui.GetWindowRect(hwnd) width = rect[2] - rect[0] height = rect[3] - rect[1] if is_child: # For children, use relative client coords (move to near top-left of parent) print("Detected child window; moving relative to parent at (10, 10)") win32gui.SetWindowPos(hwnd, win32con.HWND_TOP, 10, 10, width, height, win32con.SWP_SHOWWINDOW) else: # For top-level, use screen coords (primary monitor) print("Detected top-level window; moving to primary monitor at (100, 100)") win32gui.SetWindowPos(hwnd, win32con.HWND_TOP, x, y, width, height, win32con.SWP_SHOWWINDOW) def main(): parser = argparse.ArgumentParser(description="Window management tool for enumerating and repositioning windows.") parser.add_argument('--enumerate', action='store_true', help='Enumerate all open top-level windows (includes empty titles)') parser.add_argument('--enumerate-children', type=int, help='Enumerate child windows of the given parent hwnd') parser.add_argument('--move-window', type=int, help='Move the window with the given hwnd to visible position') args = parser.parse_args() if args.enumerate: windows = enumerate_windows(include_empty_title=True) if windows: print("Open top-level windows:") for hwnd, title, class_name in windows: print(f"Handle: {hwnd}, Title: '{title}', Class: {class_name}") else: print("No visible windows found.") elif args.enumerate_children: parent_hwnd = args.enumerate_children if not win32gui.IsWindow(parent_hwnd): print(f"Invalid parent handle: {parent_hwnd}") return children = enumerate_child_windows(parent_hwnd) if children: print(f"Child windows of parent {parent_hwnd}:") for hwnd, title, class_name in children: print(f"Handle: {hwnd}, Title: '{title}', Class: {class_name}") else: print(f"No visible child windows found for parent {parent_hwnd}.") elif args.move_window: hwnd = args.move_window console_hwnd = win32console.GetConsoleWindow() if hwnd == console_hwnd: print("Skipping move: This is the console window itself.") return try: title = win32gui.GetWindowText(hwnd) class_name = win32gui.GetClassName(hwnd) print(f"Moving window (handle: {hwnd}, title: '{title}', class: {class_name})") move_window(hwnd) except ValueError as e: print(f"Error: {e}") except Exception as e: print(f"Failed to move window: {e}") else: parser.print_help() if __name__ == "__main__": main() |
