HI

Can any one please give some idea on how to read contents of active window. i.e say i have opened some notepad file say somefile.txt n it contains some text data ....how to read the contents and display it on console or write to some log file .... user can open any .txt file so the name of the file is not constant.

Where to start from, which api to use ....

Thank you

HWND ActiveWin = GetActiveWindow();  //Gets a handle to the window..

char WindowText[256];
GetWindowTextA(ActiveWin, WindowText, 256);   //Will get the window title for u..

//Assuming the active window is notepad!
if((WindowText == "Notepad") && (ActiveWin != NULL))
{
   //read the text from notepad..
   HWND notetxt = FindWindowEx(ActiveWin, NULL, "Edit", NULL);
   int length = SendMessage(notetxt, WM_GETTEXTLENGTH, 0, 0);

   string textinside;

   int meh = SendMessage(notetxt, WM_GETTEXT, length, textinside);

   cout<<textinside;  //Prints the retrieved text to the console..
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.