If this parameter is TRUE, the two threads are attached. If the parameter is FALSE, the threads are detached.

Return Value

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.

Remarks

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.