[EDIT:] It seems my answer was so long that Superman has already provided a (much better) solution in the time I've spent typing this. Oops.
Sure thing. While the initial temptation may be to find the Notepad main window then to GetWindowText on it, this won't work. This will give you the title of the window only. The actual text area is a child window of the Notepad main window.
I'd get the handle of the main window of notepad then I would enumerate all of it's child windows. I would expect the target window to be Child #N, where N will be the same for each time you run the program.
I'd type (say) 100 characters into Notepad, then find which child window has a text length of 100 chars. This will(should!) be the edit-box that the user types into. If this window is the 2nd or 3rd child window, it should be consistently the 2nd or 3rd window - useful when the text length of the edit-window is unknown.
Here, this code will get the window title of the first running instance of Notepad found.
char *buffer;
HWND noteHwnd = NULL;
noteHwnd = FindWindowEx(NULL, NULL, "Notepad", NULL);
if (noteHwnd)
{
int len = GetWindowTextLength(noteHwnd);
if (len > 0)
{
buffer = (char*)calloc(1, len+1);
GetWindowText(noteHwnd, buffer, len+1);
printf("Number of characters found: %d\n", len);
printf("Text: %s\n", buffer);
free(buffer);
}
}
Of course, another way would be to debug a copy of Notepad. By carefull stepping through the program, you can catch the moment that the text-editing window gets created. You can then see exactly what the address is that this is stored. Coming back later you could OpenProcessMemory and read the Hwnd of the window directly from the memory that it was saved to originally. (You can use this technique of memory-reading to make a bot that will play Minesweeper for you flawlessly)
That said, I'd expect the method of enumerating the child windows of the main window to be the more effective method.
Of course, hundreds of people have probably already done just this. Searching for a finished result may well be less entertaining than deriving one yourself. That's why I never searched for a finished solution. :wink: