Changing a Window's message loop thread

Epro picture Epro · Dec 3, 2010 · Viewed 10.8k times · Source

Recently I tried putting a window's message loop in its own thread, and I wondered why it never received any messages, but I have learned that Windows posts messages to the thread that created the window. How do you create a window in one thread and cause another thread to receive that window's messages? I have seen the PostThreadMessage function but I believe that it also requires for the thread that created the window to listen for messages, which is exactly the thing I'm trying to avoid, so that function is not what I need.

This seems like it would be a common question and I have spent quite a bit of time Googling for an answer, but I can't find one.

Answer

Goz picture Goz · Dec 3, 2010

How do you create a window in one thread and cause another thread to receive that window's messages?

Simple answer ... you don't. Create the window on the thread you want to process its messages. If this is not possible then you need to re-think your approach.