


So the best approach is to use SendMessageTimeout instead of SendMessage. So if you want to be sure to get the correct text you should use WM_GETTEXT for other processes, however you should also be aware that if the window/control in question is hung SendMessage will never return. The control was created with a call to CreateWindow or CreateWindowEx with one text (that will be returned by GetWindowText) and then handles the WM_GETTEXT message itself and returns something else. This is also the reason you can get different values using GetWindowText and sending WM_GETTEXT to a control. A hung application/window shouldn't cause problems for other applications/windows. That would cause a huge problem for such things as the task switcher that would hang if one window is hung. The reason for this is simply because if GetWindowText would send the message to a window that is hung it would never return, hence hanging the process that call the function. But if you use GetWindowText on a control in another process it will return the text stored in this special memory area and not send a WM_GETTEXT message. Now, if you use the GetWindowText function it will send a WM_GETTEXT message if the window you're requesting the text for have been created by the same process that calls GetWindowText. So when you send a WM_GETTEXT message, if the window/control doesn't handle that message itself, Windows will return the string stored in the dedicated memory area when the window was created, and it will replace it if a WM_SETTEXT message is sent. In that case the control handles the WM_GETTEXT and WM_GETTEXTLENGTH messages and returns whatever text they want/use.

However the window/control can handle it themselfs, which is pretty common for a control to do. This is returned by GetWindowText or by sending WM_GETTEXT. If the system handles it it will store the text passed to CreateWindow/CreateWindowEx in a dedicated memory area. Either let system handle it or handle it themself. There is two different ways a window can handle its text.
