I don’t quite understand how GetWindowText can work for a window on the same thread as the caller. If GetWindowText blocks until the message is processed, how can the thread call DispatchMessage? It’s been blocked inside GetWindowText. Does this mean that GetWindowText must always be called from a separate thread from the one operating the message loop?
I don’t quite understand how GetWindowText can work for a window on the same
Share
GetWindowTextis just a thin wrapper forSendMessage(WM_GETTEXT).Messages sent to a window are always processed in the thread which created the window (windows have “thread affinity”). Sent messages do not go through
DispatchMessage, ratherGetMessage(orPeekMessageorMsgWaitForMultipleObjects) will call the window procedure directly, for messages sent from another thread. If the message is sent from the same thread,SendMessagewill call the window procedure.The
SendMessagedocumentation says:And the
GetMessagedocumentation says:From the
PeekMessagedocs:The behavior of sending messages has previously been highlighted on Raymond Chen’s excellent blog, The Old New Thing, which all Win32 developers ought to subscribe to:
And of course, there are related questions found here on StackOverflow: