It's not possible. Each window belongs to the thread that created it, and that ownership cannot be transferred.
It's not a matter of putting your message pump in another thread. Each thread has its own message queue. When you send or post a message to a window, the OS checks which thread owns that window and directs the message to that thread's message queue. Threads cannot read any message queue but their own, so you cannot have a thread process the messages of another thread's windows.
You could re-dispatch messages to another thread, as in the first idea in John's answer, but as a general-purpose message handler, that will become more complicated than it's worth. Many messages are meant to modify the state of the window, but you can't modify the state except from the window's own thread. Some messages are sent with the intention of getting a meaningful return value, but you can't know what to return until the message has been processed, so you'd have to block, waiting for the worker thread to process the message.
You'd be better off identifying the small set of messages that really can be off-loaded to a worker thread and handling them specially. Once you do that, you won't really have a window whose messages are handled in a different thread; you'll just have an ordinary worker thread, and it will be much less confusing to reason about.
If there are messages being sent to your window that require a lot of time to process, but the sender either doesn't need to know the result or you know the result before you finish the processing, then you can give an early response by calling ReplyMessage
. That lets the sending thread continue running while your window's thread does additional work.