C++ – Get text using SendMessage() C++


I am trying to get text from a textbox in a specific window. For this I'm using SendMessage Api function, I dont know if this is the corect way:

SendMessage(hwnd, WM_GETTEXT, 0, 0);

But I dont know how to print the text. For the argument 3 and 4 in msdn site it says: Additional message-specific information. So i dont know if I need to pass something else beside 0. I tried this also:

SendMessage(hwnd, WM_GETTEXT, sizeof(text), LPARAM(text));

But it prints the name of the textbox, I need to retrieve the text inside the box?
How can I do this? Is SendMessage() the correct API function to use ?

Thank you.


I omit to say, I am enumerating the child windows from a window, and for me it looks like a textbox, where you have to type a name. I am retrieving the username of a Instant messaging window so I cant compare it to a string, is that a textbox ?

Best Solution

You should use GetWindowText. More information here.

Related Question