Skip to content

Commit 7a3b10a

Browse files
committed
Store the window procs inside dictionaries instead of dinamically created global variables for each window
1 parent 1c1f94c commit 7a3b10a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

hPyT/hPyT.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class NCCALCSIZE_PARAMS(ctypes.Structure):
9595
rnbbcs: List[int] = []
9696
accent_color_titlebars: List[int] = []
9797
accent_color_borders: List[int] = []
98+
old_wndprocs: Dict[int, int] = {}
99+
new_wndprocs: Dict[int, int] = {}
98100

99101
WINDOWS_VERSION = float(platform.version().split(".")[0])
100102

@@ -130,11 +132,10 @@ def handle(hwnd: int, msg: int, wp: int, lp: int) -> int:
130132

131133
# Default processing for other messages
132134
return call_window_proc(
133-
*map(ctypes.c_uint64, (globals()[old], hwnd, msg, wp, lp))
135+
*map(ctypes.c_uint64, (old_wndprocs[hwnd], hwnd, msg, wp, lp))
134136
)
135137

136138
hwnd: int = module_find(window)
137-
old, new = f"old_wndproc_{hwnd}", f"new_wndproc_{hwnd}"
138139

139140
prototype = ctypes.WINFUNCTYPE(
140141
ctypes.c_uint64,
@@ -160,13 +161,13 @@ def handle(hwnd: int, msg: int, wp: int, lp: int) -> int:
160161
title_bar_height: int = full_height - client_height - border_width
161162

162163
# Override the window procedure if not already done
163-
if globals().get(old) is None:
164-
globals()[old] = get_window_long(hwnd, GWL_WNDPROC)
164+
if old_wndprocs.get(hwnd, 0) == 0:
165+
old_wndprocs[hwnd] = get_window_long(hwnd, GWL_WNDPROC)
165166

166167
# Do not remove the top border when on windows 7 or lower
167168
if WINDOWS_VERSION >= 10.0: # Windows 10 is version 10.0
168-
globals()[new] = prototype(handle)
169-
set_window_long(hwnd, GWL_WNDPROC, globals()[new])
169+
new_wndprocs[hwnd] = prototype(handle)
170+
set_window_long(hwnd, GWL_WNDPROC, new_wndprocs[hwnd])
170171

171172
old_style = get_window_long(hwnd, GWL_STYLE)
172173
new_style = (old_style & ~WS_CAPTION) | WS_BORDER
@@ -206,10 +207,10 @@ def unhide(cls, window: Any) -> None:
206207

207208
hwnd: int = module_find(window)
208209

209-
if globals().get(f"old_wndproc_{hwnd}") is not None:
210-
set_window_long(hwnd, GWL_WNDPROC, globals()[f"old_wndproc_{hwnd}"])
211-
globals()[f"old_wndproc_{hwnd}"] = None
212-
globals()[f"new_wndproc_{hwnd}"] = None
210+
if old_wndprocs.get(hwnd, 0) != 0:
211+
set_window_long(hwnd, GWL_WNDPROC, old_wndprocs[hwnd])
212+
old_wndprocs.pop(hwnd)
213+
new_wndprocs.pop(hwnd)
213214

214215
# Restore the original height if no_span was used
215216
height_reduction: int = cls._height_reduction.pop(hwnd, 0)

0 commit comments

Comments
 (0)