Skip to content

Commit 1a710e6

Browse files
committed
Add toggle_cloak method to window_dwm class for window invisibility control
1 parent c2467b8 commit 1a710e6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

hPyT/hPyT.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ctypes.wintypes
12
import math
23
import threading
34
import time
@@ -1367,6 +1368,39 @@ def toggle_rtl_layout(cls, window: Any, enabled: bool = True) -> None:
13671368
4,
13681369
)
13691370

1371+
@classmethod
1372+
def toggle_cloak(cls, window: Any, enabled: bool = True) -> None:
1373+
"""
1374+
Toggle window cloaking (invisibility while still being composed by DWM).
1375+
Useful for DirectComposition animations and special effects.
1376+
Note: Only supported on Windows 8 and later.
1377+
1378+
Args:
1379+
window (object): The window object to modify.
1380+
enabled (bool): True to cloak (hide) the window, False to uncloak (show).
1381+
1382+
Example:
1383+
# Cloak (hide) the window
1384+
>>> window_dwm.toggle_cloak(window, True)
1385+
1386+
# Uncloak (show) the window
1387+
>>> window_dwm.toggle_cloak(window, False)
1388+
1389+
Notes:
1390+
- Window remains composed by DWM even when cloaked
1391+
- Particularly useful with DirectComposition for layered child window animations
1392+
- Does not affect window functionality, only visibility
1393+
"""
1394+
hwnd: int = module_find(window)
1395+
1396+
# DWMWA_CLOAK = 13
1397+
ctypes.windll.dwmapi.DwmSetWindowAttribute(
1398+
hwnd,
1399+
13, # DWMWA_CLOAK
1400+
ctypes.byref(ctypes.wintypes.BOOL(enabled)),
1401+
ctypes.sizeof(ctypes.wintypes.BOOL(enabled)),
1402+
)
1403+
13701404

13711405
class title_text:
13721406
"""Play with the title of a window."""

0 commit comments

Comments
 (0)