How To Create Windows in a Multithreaded Application

Article translations Article translations
Article ID: 90975 - View products that this article applies to.
This article was previously published under Q90975
Expand all | Collapse all


In a multithreaded application, any thread can call the CreateWindow() API to create a window. There are no restrictions on which thread(s) can create windows.

It is important to note that the message loop and window procedure for the window must be in the thread that created the window. If a different thread creates the window, the window won't get messages from DispatchMessage(), but will get messages from other sources. Therefore, the window will appear but won't show activation or repaint, cannot be moved, won't receive mouse messages, and so on.


Normally, windows created in different threads process input independently of each other. The windows have their own input states and the threads are not synchronized with eachother in regards to input processing.

In order to have threads to share input state, have one thread call AttachThreadInput() to have its input processing attached to another thread. What this means is that these two threads will use a Windows 3.1 style system queue. The threads will still have separate input, but they will take turns reading out of the same queue.

Creating a window can force an implicit AttachThreadInput(), when a parent window is created in one thread and the child window is being created in another thread. When windows are created (or set) in separate threads with a parent-child relationship, the input queues are attached.

On Windows NT/2000, you cannot use AttachThreadInput() to attach a thread to a thread in another desktop.


Article ID: 90975 - Last Review: July 11, 2005 - Revision: 1.3
  • Microsoft Platform Software Development Kit-January 2000 Edition
kbhowto kbwndw KB90975

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from