I am trying to get the text from a text window. However, the GetWindowText() call keeps on getting me the text in the window header and not the text in the window itself... I have read up on the function call and seen that this happens if you call it from another process or something along those lines... but I can't seem to understand how that can be the case.
My function is copied from an existing function that saves the text to a file. That save function works just fine. Both functions are called in the same way so I don't see how any process conflict would happen in my case only.
Here is my function that I call when I want to get the text and process it (here it is written to a test file for monitoring purposes):
void GetTextFromEdit(HWND hEdit)
{
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
//Do nothing if there is no text.
if(dwTextLength > 0)
{
LPSTR pszText;
DWORD dwBufferSize = dwTextLength + 1;
pszText = (LPSTR)GlobalAlloc(GPTR, dwBufferSize);
if(pszText != NULL)
{
if(GetWindowText(hEdit, pszText, dwBufferSize))
{
string myString=pszText;
writeFile("trash11.txt",myString);
}
GlobalFree(pszText);
}
}
}
Any ideas as to what is going on? I even tried with a sendmessage/WM_GETTEXT but with the same results...
My code is based on the excellent API tutorial given here (app_two):