88 lines
2.5 KiB
Python
88 lines
2.5 KiB
Python
from ctypes import POINTER, WINFUNCTYPE, WinError, create_unicode_buffer, get_last_error, windll
|
|
from ctypes.wintypes import BOOL, DWORD, HBRUSH, HDC, HINSTANCE, HMENU, HWND, LPARAM, LPCWSTR, LPVOID, LPWSTR, INT, RECT
|
|
import time
|
|
|
|
user32 = windll.user32
|
|
gdi32 = windll.gdi32
|
|
|
|
CB_ENUM_WINDOWS = WINFUNCTYPE(BOOL, HWND, LPARAM)
|
|
|
|
# thanks: https://stackoverflow.com/questions/37501191/how-to-get-windows-window-names-with-ctypes-in-python
|
|
def check_zero(result, func, args):
|
|
if not result:
|
|
err = get_last_error()
|
|
if err:
|
|
raise WinError(err)
|
|
return args
|
|
|
|
user32.CreateWindowExW.argtypes = [
|
|
DWORD, LPCWSTR, LPCWSTR, DWORD,
|
|
INT, INT, INT, INT,
|
|
HWND, HMENU, HINSTANCE, LPVOID
|
|
]
|
|
user32.CreateWindowExW.errcheck = check_zero
|
|
|
|
user32.FillRect.argtypes = [HDC, POINTER(RECT), HBRUSH]
|
|
|
|
user32.GetWindowDC.argtypes = [HWND]
|
|
user32.GetWindowDC.errcheck = check_zero
|
|
|
|
user32.GetWindowTextLengthW.argtypes = [HWND]
|
|
user32.GetWindowTextLengthW.errcheck = check_zero
|
|
|
|
user32.GetWindowTextW.argtypes = [HWND, LPWSTR, INT]
|
|
user32.GetWindowTextW.errcheck = check_zero
|
|
|
|
def find_all_windows():
|
|
windows = []
|
|
|
|
@CB_ENUM_WINDOWS
|
|
def _handle_window(hwnd, lparam):
|
|
# +1: make room for the null
|
|
length = user32.GetWindowTextLengthW(hwnd) + 1
|
|
buffer = create_unicode_buffer(length)
|
|
user32.GetWindowTextW(hwnd, buffer, length)
|
|
windows.append((hwnd, buffer.value))
|
|
return True
|
|
|
|
user32.EnumWindows(_handle_window, 0)
|
|
return windows
|
|
|
|
def fix_window(window):
|
|
"""
|
|
hdc = user32.GetWindowDC(window)
|
|
rect = RECT(0, 0, 10000, 10000)
|
|
brush = gdi32.CreateSolidBrush(0x00FF0000)
|
|
user32.FillRect(hdc, rect, brush)
|
|
gdi32.DeleteObject(brush)
|
|
print(window)
|
|
"""
|
|
classname = create_unicode_buffer("overlapper\x00")
|
|
windowname = create_unicode_buffer("overlapper\x00")
|
|
window = user32.CreateWindowExW(
|
|
0x08000000 | # WS_EX_NOACTIVATE
|
|
0x8 | # WS_EX_TOPMOST
|
|
0x0, # 0x20, # WS_EX_TRANSPARENT
|
|
classname,
|
|
windowname,
|
|
0x10000000, # WS_VISIBLE
|
|
0, 0, 128, 128, # x y w h
|
|
None, None,
|
|
None, None
|
|
)
|
|
user32.ShowWindow(window, 5) # SW_SHOW
|
|
|
|
def fix_step():
|
|
windows = find_all_windows()
|
|
for window_id, window_name in windows:
|
|
if window_name.endswith("Visual Studio Code"):
|
|
fix_window(window_id)
|
|
|
|
def main():
|
|
fix_step()
|
|
|
|
while True:
|
|
time.sleep(1)
|
|
|
|
if __name__ == "__main__":
|
|
main() |