def _attach_message_queue_to_thread(current_hwnd):
current_thread_id = windll.kernel32.GetCurrentThreadId()
thread_process_id = windll.user32.GetWindowThreadProcessId(current_hwnd, None)
if thread_process_id != current_thread_id:
res = windll.user32.AttachThreadInput(thread_process_id, current_thread_id, True)
# ERROR_INVALID_PARAMETER means that the two threads are already attached.
if res == 0 and GetLastError() != ERROR_INVALID_PARAMETER:
# TODO better logging
print("WARN: could not attach thread input to thread {0} ({1})".format(thread_process_id, GetLastError()))
return True
windll.user32.AttachThreadInput(thread_process_id, current_thread_id, False)
return False
评论列表
文章目录