From 7ed90aee83c4bb4092facd39120b6c333f209150 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 19 Jan 2021 11:54:17 +0000 Subject: [PATCH] Comment EnumWindows()/enumwindowsproc() to document function. --- EDMarketConnector.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 30b013fc..0ce765bd 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -123,6 +123,19 @@ if __name__ == '__main__': # noqa: C901 @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) def enumwindowsproc(window_handle, l_param): + """ + Determine if any window for the Application exists. + + Called for each found window by EnumWindows(). + + When a match is found we check if we're being invoked as the + edmc://auth handler. If so we send the message to the existing + process/window. If not we'll raise that existing window to the + foreground. + :param window_handle: Window to check. + :param l_param: ??? + :return: False if we found a match, else True to continue iteration + """ # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 cls = ctypes.create_unicode_buffer(257) # This conditional is exploded to make debugging slightly easier @@ -141,10 +154,18 @@ if __name__ == '__main__': # noqa: C901 ShowWindowAsync(window_handle, SW_RESTORE) SetForegroundWindow(window_handle) + return False # Indicate window found, so stop iterating + + # Indicate that EnumWindows() needs to continue iterating return True # Do not remove, else this function as a callback breaks # This performs the edmc://auth check and forward + # EnumWindows() will iterate through all open windows, calling + # enumwindwsproc() on each. When an invocation returns False it + # stops iterating. + # Ref: EnumWindows(enumwindowsproc, 0) + return False # Another instance is running else: