I have a situation where I want to SendMessage
to a window that was created on another thread than the one that is calling SendMessage
.
The default behaviour seems to be block forever and not work.
So I changed the call to PostMessage
, which didn't block the sending thread, but the message never appears to arrive at the intended window.
So how do I SendMessage
to a window created on a separate thread, or is this impossible?
What is the thread that owns the target window doing? It needs to be pumping messages in order to be able to receive messages that are either sent or posted to it. Typically this is done by having a GetMessage/TranslateMessage/DispatchMessage loop. If the thread is doing something else - such as blocking waiting for an event or mutex or IO to complete, or is busy in some other loop carrying out a calculation, it won't receive messages: SendMessage to the thread will block, and PostMessage will post but not get delivered.
If that target thread needs to both manage events or similar, and it also owns a window, you may need to use MsgWaitForMultipleObjects in that thread's message loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With