From c5d9fe4541cf35fd13e3cbc6d46f8ae2a7e05877 Mon Sep 17 00:00:00 2001 From: alexpolo1 Date: Fri, 7 Aug 2026 14:33:07 +0200 Subject: [PATCH] fix: catch SetWindowPos access denied in all window functions Wraps SetWindowPos in try/except pywintypes.error in move_d2r_window, set_d2r_always_on_top, and restore_d2r_window_visibility. When D2R runs as Administrator, Windows denies the call. Bot now continues gracefully instead of crashing. --- src/utils/misc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/misc.py b/src/utils/misc.py index 28c7d3f..5cf894f 100644 --- a/src/utils/misc.py +++ b/src/utils/misc.py @@ -184,7 +184,11 @@ def move_d2r_window(client_x, client_y, client_width=None, client_height=None): outer_y = client_y - (client_top - wr_top) outer_w = (client_width if client_width else (c_right - c_left)) + border_w outer_h = (client_height if client_height else (c_bottom - c_top)) + border_h - SetWindowPos(hwnd, HWND_TOPMOST, outer_x, outer_y, outer_w, outer_h, SWP_SHOWWINDOW) + try: + SetWindowPos(hwnd, HWND_TOPMOST, outer_x, outer_y, outer_w, outer_h, SWP_SHOWWINDOW) + except pywintypes.error: + Logger.debug("SetWindowPos denied in move_d2r_window (D2R elevated) — skipping") + return False Logger.debug( f"Moved D2R client area to ({client_x}, {client_y}) " f"with size {client_width or c_right - c_left}x{client_height or c_bottom - c_top}"