1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-10 04:12:15 +03:00

[1805] Additional Handover

This commit is contained in:
David Sangrey 2024-06-11 11:06:58 -04:00
parent f8d354a4dd
commit 571558daff
No known key found for this signature in database
GPG Key ID: 3AEADBB0186884BC
3 changed files with 10 additions and 10 deletions

View File

@ -260,10 +260,10 @@ if __name__ == '__main__': # noqa: C901
from ctypes.wintypes import BOOL, HWND, LPARAM from ctypes.wintypes import BOOL, HWND, LPARAM
import win32gui import win32gui
import win32api import win32api
import win32con
GetProcessHandleFromHwnd = windll.oleacc.GetProcessHandleFromHwnd # noqa: N806 GetProcessHandleFromHwnd = windll.oleacc.GetProcessHandleFromHwnd # noqa: N806
SW_RESTORE = 9 # noqa: N806
ShowWindow = windll.user32.ShowWindow # noqa: N806 ShowWindow = windll.user32.ShowWindow # noqa: N806
ShowWindowAsync = windll.user32.ShowWindowAsync # 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): if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect):
CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)
# Wait for it to be responsive to avoid ShellExecute recursing # Wait for it to be responsive to avoid ShellExecute recursing
ShowWindow(window_handle, SW_RESTORE) ShowWindow(window_handle, win32con.SW_RESTORE)
win32api.ShellExecute(0, None, sys.argv[1], None, None, SW_RESTORE) win32api.ShellExecute(0, None, sys.argv[1], None, None, win32con.SW_RESTORE)
else: else:
ShowWindowAsync(window_handle, SW_RESTORE) ShowWindowAsync(window_handle, win32con.SW_RESTORE)
win32gui.SetForegroundWindow(window_handle) win32gui.SetForegroundWindow(window_handle)
return False # Indicate window found, so stop iterating return False # Indicate window found, so stop iterating

View File

@ -49,7 +49,7 @@ def window_title(h) -> str:
if h: if h:
title_length = win32gui.GetWindowTextLength(h) + 1 title_length = win32gui.GetWindowTextLength(h) + 1
buf = ctypes.create_unicode_buffer(title_length) buf = ctypes.create_unicode_buffer(title_length)
if win32gui.GetWindowText(h, buf, title_length): if win32gui.GetWindowText(h):
return buf.value return buf.value
return '' return ''

View File

@ -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, ATOM, BOOL, DWORD, HBRUSH, HGLOBAL, HICON, HINSTANCE, HMENU, HWND, INT, LPARAM, LPCWSTR, LPMSG, LPVOID, LPWSTR,
MSG, UINT, WPARAM MSG, UINT, WPARAM
) )
from win32con import CW_USEDEFAULT
import win32gui
import win32con
class WNDCLASS(Structure): class WNDCLASS(Structure):
""" """
@ -98,7 +101,6 @@ if (config.auth_force_edmc_protocol # noqa: C901
('lpszClassName', LPCWSTR) ('lpszClassName', LPCWSTR)
] ]
CW_USEDEFAULT = 0x80000000
CreateWindowExW = windll.user32.CreateWindowExW CreateWindowExW = windll.user32.CreateWindowExW
CreateWindowExW.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID] 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") paramflags = (1, "hWnd"), (1, "Msg"), (1, "wParam"), (1, "lParam")
DefWindowProcW = prototype(("DefWindowProcW", windll.user32), paramflags) DefWindowProcW = prototype(("DefWindowProcW", windll.user32), paramflags)
GetParent = windll.user32.GetParent
SetForegroundWindow = windll.user32.SetForegroundWindow SetForegroundWindow = windll.user32.SetForegroundWindow
# <https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew> # <https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew>
@ -132,7 +133,6 @@ if (config.auth_force_edmc_protocol # noqa: C901
PostMessageW = windll.user32.PostMessageW PostMessageW = windll.user32.PostMessageW
PostMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] PostMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM]
WM_QUIT = 0x0012
# https://docs.microsoft.com/en-us/windows/win32/dataxchg/wm-dde-initiate # https://docs.microsoft.com/en-us/windows/win32/dataxchg/wm-dde-initiate
WM_DDE_INITIATE = 0x03E0 WM_DDE_INITIATE = 0x03E0
WM_DDE_TERMINATE = 0x03E1 WM_DDE_TERMINATE = 0x03E1
@ -229,7 +229,7 @@ if (config.auth_force_edmc_protocol # noqa: C901
thread = self.thread thread = self.thread
if thread: if thread:
self.thread = None 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 thread.join() # Wait for it to quit
def worker(self) -> None: def worker(self) -> None:
@ -291,7 +291,7 @@ if (config.auth_force_edmc_protocol # noqa: C901
logger.debug(f'Message starts with {self.redirect}') logger.debug(f'Message starts with {self.redirect}')
self.event(url) 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 # 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)) PostMessageW(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam))