Process and Thread Function ...


AttachThreadInput Function

Attaches or detaches the input processing mechanism of one thread to that of another thread.

Syntax

C++
BOOL WINAPI AttachThreadInput(
  __in  DWORD idAttach,
  __in  DWORD idAttachTo,
  __in  BOOL fAttach
);

Parameters

idAttach [in]

The identifier of the thread to be attached to another thread. The thread to be attached cannot be a system thread.

idAttachTo [in]

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.

fAttach [in]

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/2000:  There is no extended error information; do not call GetLastError. This behavior changed as of Windows Vista.

Remarks

Windows created in different threads typically process input independently of each other. That is, they have their own input states (focus, active, capture windows, key state, queue status, and so on), and they are not synchronized with the input processing of other threads. By using the AttachThreadInput function, a thread can attach its input processing to another thread. This also allows threads to share their input states, so they can call the SetFocus function to set the keyboard focus to a window of a different thread. This also allows threads to get key-state information. These capabilities are not generally possible.

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.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinuser.h (include Windows.h)
LibraryUser32.lib
DLLUser32.dll

See Also

GetCurrentThreadId
GetKeyState
GetKeyboardState
GetWindowThreadProcessId
Process and Thread Functions
SetFocus
Threads

Send comments about this topic to Microsoft

Build date: 10/8/2009

Tags :


Community Content

dmex
vb.net syntax
<DllImport("user32", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function AttachThreadInput(ByVal idAttach As Integer, ByVal idAttachTo As Integer, ByVal fAttach As Integer) As Integer
End Function
Tags : vb.net syntax

dmex
C# syntax
[DllImport("user32", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
internal static extern int AttachThreadInput(int idAttach, int idAttachTo, int fAttach);
Tags : c# syntax

Page view tracker