Skip to content

Commit

Permalink
[1805] Additional Handover
Browse files Browse the repository at this point in the history
  • Loading branch information
Rixxan committed Jun 11, 2024
1 parent f8d354a commit 571558d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def handle_edmc_callback_or_foregrounding() -> None: # noqa: CCR001
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

Expand Down Expand Up @@ -308,11 +308,11 @@ def enumwindowsproc(window_handle, l_param): # noqa: CCR001
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
Expand Down
2 changes: 1 addition & 1 deletion hotkey/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
10 changes: 5 additions & 5 deletions protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def event(self, url: str) -> None:
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):
"""
Expand All @@ -98,7 +101,6 @@ class WNDCLASS(Structure):
('lpszClassName', LPCWSTR)
]

CW_USEDEFAULT = 0x80000000

CreateWindowExW = windll.user32.CreateWindowExW

Check failure on line 105 in protocol.py

View workflow job for this annotation

GitHub Actions / push_checks

E303 too many blank lines (2)
CreateWindowExW.argtypes = [DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID]
Expand All @@ -114,7 +116,6 @@ class WNDCLASS(Structure):
paramflags = (1, "hWnd"), (1, "Msg"), (1, "wParam"), (1, "lParam")
DefWindowProcW = prototype(("DefWindowProcW", windll.user32), paramflags)

GetParent = windll.user32.GetParent
SetForegroundWindow = windll.user32.SetForegroundWindow

# <https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew>
Expand All @@ -132,7 +133,6 @@ class WNDCLASS(Structure):
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
Expand Down Expand Up @@ -229,7 +229,7 @@ def close(self) -> None:
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:
Expand Down Expand Up @@ -291,7 +291,7 @@ def worker(self) -> None:
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))

Expand Down

0 comments on commit 571558d

Please sign in to comment.