Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   what different GetwindowText To WM_GetTEXT (http://www.go4expert.com/forums/getwindowtext-wmgettext-t20922/)

NOV 9Feb2010 15:30

what different GetwindowText To WM_GetTEXT
 
i have read 1 post on internet

Quote:

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

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. This is the default behaviour.

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. 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. 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. That would cause a huge problem for such things as the task switcher that would hang if one window is hung. A hung application/window shouldn't cause problems for other applications/windows.

This is also the reason you can get different values using GetWindowText and sending WM_GETTEXT to a control. 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. 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. So the best approach is to use SendMessageTimeout instead of SendMessage.
__________________
why i hook

SetWindowsHookEx(WH_GETMESSAGE,GetMesgProc,g_hModu le,0);but dont catch event GetWindowText in current App ?


All times are GMT +5.5. The time now is 21:24.