AttachThreadInput function (winuser.h)
Attaches or detaches the input processing mechanism of one thread to that of another thread.
BOOL AttachThreadInput( DWORD idAttach, DWORD idAttachTo, BOOL fAttach );
The identifier of the thread to be attached to another thread. The thread to be attached cannot be a system thread.
The identifier of the thread to which idAttach will be attached. This thread cannot be a system thread.
A thread cannot attach to itself. Therefore, idAttachTo cannot equal idAttach.
If this parameter is TRUE, the two threads are attached. If the parameter is FALSE, the threads are detached.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Windows Server 2003 and Windows XP: There is no extended error information; do not call GetLastError. This behavior changed as of Windows Vista.
By using the AttachThreadInput function, a thread can share its input states (such as keyboard states and the current focus window) with another thread. Keyboard and mouse events received by both threads are processed in the order they were received until the threads are detached by calling AttachThreadInput a second time and specifying FALSE for the fAttach parameter.
The AttachThreadInput function fails if either of the specified threads does not have a message queue. The system creates a thread's message queue when the thread makes its first call to one of the USER or GDI functions. The AttachThreadInput function also fails if a journal record hook is installed. Journal record hooks attach all input queues together.
Note that key state, which can be ascertained by calls to the GetKeyState or GetKeyboardState function, is reset after a call to AttachThreadInput. You cannot attach a thread to a thread in another desktop.
|Minimum supported client||Windows XP [desktop apps only]|
|Minimum supported server||Windows Server 2003 [desktop apps only]|
|Header||winuser.h (include Windows.h)|
|API set||ext-ms-win-ntuser-misc-l1-2-0 (introduced in Windows 8.1)|