diff --git a/EDMarketConnector.py b/EDMarketConnector.py index e48a927c..0cd34486 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -260,10 +260,10 @@ if __name__ == '__main__': # noqa: C901 from ctypes.wintypes import BOOL, HWND, LPARAM import win32gui import win32api + import win32con GetProcessHandleFromHwnd = windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 - SW_RESTORE = 9 # noqa: N806 ShowWindow = windll.user32.ShowWindow # noqa: N806 ShowWindowAsync = windll.user32.ShowWindowAsync # noqa: N806 @@ -308,11 +308,11 @@ if __name__ == '__main__': # noqa: C901 if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect): CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) # Wait for it to be responsive to avoid ShellExecute recursing - ShowWindow(window_handle, SW_RESTORE) - win32api.ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) + ShowWindow(window_handle, win32con.SW_RESTORE) + win32api.ShellExecute(0, None, sys.argv[1], None, None, win32con.SW_RESTORE) else: - ShowWindowAsync(window_handle, SW_RESTORE) + ShowWindowAsync(window_handle, win32con.SW_RESTORE) win32gui.SetForegroundWindow(window_handle) return False # Indicate window found, so stop iterating diff --git a/hotkey/windows.py b/hotkey/windows.py index 51da80be..95b1a83a 100644 --- a/hotkey/windows.py +++ b/hotkey/windows.py @@ -49,7 +49,7 @@ def window_title(h) -> str: if h: title_length = win32gui.GetWindowTextLength(h) + 1 buf = ctypes.create_unicode_buffer(title_length) - if win32gui.GetWindowText(h, buf, title_length): + if win32gui.GetWindowText(h): return buf.value return '' diff --git a/protocol.py b/protocol.py index 1fb88595..eed14b44 100644 --- a/protocol.py +++ b/protocol.py @@ -76,6 +76,9 @@ if (config.auth_force_edmc_protocol # noqa: C901 ATOM, BOOL, DWORD, HBRUSH, HGLOBAL, HICON, HINSTANCE, HMENU, HWND, INT, LPARAM, LPCWSTR, LPMSG, LPVOID, LPWSTR, MSG, UINT, WPARAM ) + from win32con import CW_USEDEFAULT + import win32gui + import win32con class WNDCLASS(Structure): """ @@ -98,7 +101,6 @@ if (config.auth_force_edmc_protocol # noqa: C901 ('lpszClassName', LPCWSTR) ] - CW_USEDEFAULT = 0x80000000 CreateWindowExW = windll.user32.CreateWindowExW CreateWindowExW.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID] @@ -114,7 +116,6 @@ if (config.auth_force_edmc_protocol # noqa: C901 paramflags = (1, "hWnd"), (1, "Msg"), (1, "wParam"), (1, "lParam") DefWindowProcW = prototype(("DefWindowProcW", windll.user32), paramflags) - GetParent = windll.user32.GetParent SetForegroundWindow = windll.user32.SetForegroundWindow # @@ -132,7 +133,6 @@ if (config.auth_force_edmc_protocol # noqa: C901 PostMessageW = windll.user32.PostMessageW PostMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] - WM_QUIT = 0x0012 # https://docs.microsoft.com/en-us/windows/win32/dataxchg/wm-dde-initiate WM_DDE_INITIATE = 0x03E0 WM_DDE_TERMINATE = 0x03E1 @@ -229,7 +229,7 @@ if (config.auth_force_edmc_protocol # noqa: C901 thread = self.thread if thread: self.thread = None - PostThreadMessageW(thread.ident, WM_QUIT, 0, 0) + PostThreadMessageW(thread.ident, win32con.WM_QUIT, 0, 0) thread.join() # Wait for it to quit def worker(self) -> None: @@ -291,7 +291,7 @@ if (config.auth_force_edmc_protocol # noqa: C901 logger.debug(f'Message starts with {self.redirect}') self.event(url) - SetForegroundWindow(GetParent(self.master.winfo_id())) # raise app window + SetForegroundWindow(win32gui.GetParent(self.master.winfo_id())) # raise app window # Send back a WM_DDE_ACK. this is _required_ with WM_DDE_EXECUTE PostMessageW(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam))