Reputation: 621
I have read that I should only use PostMessage()
to tell the UI thread to access the UI controls.
There is no problem in following this approach if I am for example setting the text of an "EDIT"
control. However, what if I want to get the text of an "EDIT"
control, if I send a message to the UI thread using PostMessage()
, then PostMessage()
will return immediately before the text is set into the buffer, so how should I solve this problem?
Upvotes: 0
Views: 109
Reputation: 612794
You cannot use PostMessage
for this purpose for the reasons that you identify. WM_GETTEXT
is a synchronous message. What you should do is:
GetWindowText
. SendMessageTimeout
.Why SendMessageTimeout
rather than SendMessage
? Well, if the other process has hung and is not responding, then using SendMessage
would never return.
There is more discussion of this topic here: The secret life of GetWindowText.
Upvotes: 2