Introduction
This article will tell you how you can retrieve the text from any window. I will use the Notepad as the sample but you can even use the password input boxes. This is not about hacking the passwords but is for retrieving you lost but saved password which is not displayed in browser. There is no standard approach for changing or retrieving the text from existing windows.
How to go about it?
In windows every window has handle which is assigned when process of window is created. Which is unique across all processes. Window means not only top level windows but also buttons, text boxes and other controls. Handle is required to interact with these windows.
Finding a window handle
There are number of ways to find the window handle. For sample application of Notepad an API FindWindow() function is useful. It takes class name and window name as parameters and returns handle to the window. Spy++ (The bundle application with the Visual studio) is a good application to find the class name.
For Notepad the class name is 'notepad'.
Code: CPP
HWND hNotepad = ::FindWindow(_T("notepad"),NULL);
if(hNotepad == NULL)
{
MessageBox(_T("No Notepad present"));
}
Using this control ID, child widow handle can retrieved as follows
Code: CPP
HWND hEdit = ::GetDlgItem(hNotepad,0xf);
Get the text
Using windows message WM_SETTEXT and WM_GETTEXT you can get the text of the notepad or set it.
Code: CPP
TCHAR txtBuf[256];
memset(txtBuf,0,sizeof(TCHAR));
::SendMessage(hEdit,WM_GETTEXT,(WPARAM)1024,(LPARAM)txtBuf);
