0

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):

http://www.winprog.org/tutorial/

Edited by Reverend Jim: Fixed formatting

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by seakayaker
0

... issue solved. I didnt realize that my function was called with a window handler. I just had to point to the edit box handler in the routine and now everything works.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.