I am trying to retrieve the text of a button on Calculator (calc.exe) using Winapi. I have hooked WH_CALLWNDPROC and the hook works fine. But I am unable to retrieve the text of any button (say numeric 7). I am using GetDlgItemText:
TCHAR text[256];
GetDlgItemText((HWND)0x7068c, 0x89, text, strlen(text));
Here 0x7068c is the parent window handle of the numeric 7 button, while 0x89 is its control id. No text is returned, though I am able to click it programmatically.
What am I doing wrong? I tried to use SendMessage with WM_GETTEXT, but it still doesnt work. I want to take this approach and retrieve the text from buttons, textboxes in other applications.
I finally succeeded in doing this by using EasyHook for hooking DrawTextW, DrawTextExW, ExtTextOutW API functions for retrieving the text off buttons, labels, etc. In the hooked functions I was able to retrieve the text. This SO thread was a great help to me.