Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text using SendMessage() C++

Tags:

c++

winapi

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.

edit:

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 ?

like image 441
Adrian Avatar asked Dec 07 '25 10:12

Adrian


2 Answers

You should use GetWindowText. More information here.

like image 121
Mac Avatar answered Dec 10 '25 01:12

Mac


Read the MSDN documentation again. It does NOT say "Additional message-specific information" for those parameters:

wParam The maximum number of characters to be copied, including the terminating null character.

ANSI applications may have the string in the buffer reduced in size (to a minimum of half that of the wParam value) due to conversion from ANSI to Unicode.

lParam A pointer to the buffer that is to receive the text.

like image 44
Remy Lebeau Avatar answered Dec 09 '25 23:12

Remy Lebeau