diff --git a/monitor.py b/monitor.py index 63c05d65..466aac37 100644 --- a/monitor.py +++ b/monitor.py @@ -50,8 +50,9 @@ if sys.platform == 'darwin': elif sys.platform == 'win32': import ctypes from ctypes import WINFUNCTYPE, windll - from ctypes.wintypes import BOOL, HANDLE, HWND, LPARAM, LPWSTR + from ctypes.wintypes import BOOL, HANDLE, HWND, LPARAM + import win32gui from watchdog.events import FileCreatedEvent, FileSystemEventHandler from watchdog.observers import Observer @@ -73,24 +74,6 @@ elif sys.platform == 'win32': paramflags_closehandle = (1, "hObject"), CloseHandle = prototype(("CloseHandle", windll.kernel32), paramflags_closehandle) - # - # int GetWindowTextW( - # [in] HWND hWnd, - # [out] LPWSTR lpString, - # [in] int nMaxCount - # ); - prototype = WINFUNCTYPE(ctypes.c_int, HWND, LPWSTR, ctypes.c_int) - paramflags_getwindowtextw = (1, "hWnd"), (2, "lpString"), (1, "nMaxCount") - GetWindowTextW = prototype(("GetWindowTextW", windll.user32), paramflags_getwindowtextw) - - # - # int GetWindowTextLengthW( - # [in] HWND hWnd - # ); - prototype = WINFUNCTYPE(ctypes.c_int, HWND) - paramflags_getwindowtextlengthw = (1, "hWnd"), - GetWindowTextLengthW = prototype(("GetWindowTextLengthW", windll.user32), paramflags_getwindowtextw) - GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd else: @@ -2060,10 +2043,8 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below elif sys.platform == 'win32': def WindowTitle(h): # noqa: N802 # type: ignore if h: - length = GetWindowTextLengthW(h) + 1 - buf = ctypes.create_unicode_buffer(length) - if GetWindowTextW(h, buf, length): - return buf.value + return win32gui.GetWindowText(h) + return None def callback(hWnd, lParam): # noqa: N803 diff --git a/requirements-dev.txt b/requirements-dev.txt index 6a0ace7f..30b23df4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -48,8 +48,6 @@ pytest==7.2.0 pytest-cov==4.0.0 # Pytest code coverage support coverage[toml]==7.0.5 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs coverage-conditional-plugin==0.8.0 -# For manipulating folder permissions and the like. -pywin32==305; sys_platform == 'win32' # All of the normal requirements diff --git a/requirements.txt b/requirements.txt index 5244e2f0..736ed50b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,5 +7,8 @@ infi.systray==0.1.12; sys_platform == 'win32' # pyyaml==5.3.1 watchdog dep semantic-version==2.10.0 +# Used both by some tests *and* now in monitor.py +pywin32==305; sys_platform == 'win32' + # Base requirement for MacOS pyobjc; sys_platform == 'darwin'