I am trying to get the text on the textbox of a notepad window using the SendMessage from the win32 api. I find the window handle first, and I grab the text with SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)textBuffer). For some reason, even though it can tell me the correct length of the text, the program only returns 1 character of the notepad text, even when I have 1024 as my buffersize which it should be returning. I looked at examples I found, and the way I do it is the same as the examples. I have no clue why this is happening, can someone help me out or point out my error?
#include <Windows.h>
#include <iostream>
int main()
{
printf("finding notepad window\n");
HWND hwndNotepad = FindWindow(NULL, L"Untitled - Notepad");
if(NULL != hwndNotepad)
{
printf("Find edit control window\n");
HWND hwndEdit = FindWindowEx(hwndNotepad, NULL, L"EDIT", NULL);
if(NULL != hwndEdit)
{
printf("- get text length\n");
int textLen = (int)SendMessage(hwndEdit, WM_GETTEXTLENGTH, 0, 0);
printf("textlength: %d\n", textLen);
if(0 < textLen)
{
const int bufferSize = 1024;
char textBuffer[bufferSize] = "";
SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)textBuffer);
printf("getting text:\n");
printf("%s\n", textBuffer);
}
else
{
printf("its empty\n");
}
}
else
{
printf("I cant find this control\n");
}
}
else
{
printf("I cant find notepad window. \n");
}
return 0;
}
Screenshot: http://i.imgur.com/bUhVqlq.png