1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-24 12:40:52 +03:00

startup/one-process: Convert window_title() to pywin32

This commit is contained in:
Athanasius 2023-01-13 14:18:21 +00:00
parent 85ed69463c
commit 30239a4916
No known key found for this signature in database
GPG Key ID: 772697E181BB2767

View File

@ -246,6 +246,10 @@ if __name__ == '__main__': # noqa: C901
# now need to do the edmc:// checks for auth callback
if locked != JournalLockResult.LOCKED:
import ctypes
import win32api
import win32con
import win32gui
import win32process
from ctypes.wintypes import BOOL, HWND, INT, LPARAM, LPCWSTR, LPWSTR
EnumWindows = ctypes.windll.user32.EnumWindows # noqa: N806
@ -253,7 +257,6 @@ if __name__ == '__main__': # noqa: C901
GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int]
GetWindowText = ctypes.windll.user32.GetWindowTextW # noqa: N806
GetWindowText.argtypes = [HWND, LPWSTR, ctypes.c_int]
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW # noqa: N806
GetProcessHandleFromHwnd = ctypes.windll.oleacc.GetProcessHandleFromHwnd # noqa: N806
SW_RESTORE = 9 # noqa: N806
@ -271,10 +274,7 @@ if __name__ == '__main__': # noqa: C901
def window_title(h: int) -> Optional[str]:
if h:
text_length = GetWindowTextLength(h) + 1
buf = ctypes.create_unicode_buffer(text_length)
if GetWindowText(h, buf, text_length):
return buf.value
return win32gui.GetWindowText(h)
return None