Hi
Is it possible via C# to capture content of a window in a windows application?
I have an application(mp3 player) with several windows and in one of them there are lines of text(names of the mp3 files). I want to to capture what filename is selected and activated(played).
I have some hunch that it might be the process class I have to use, but how do I tell it what window to capture from and what filename is selected and activated?
Loading
AlanPosted Oct 17, 2008, 10:13 AM
One thing that might work is to copy the selected text to the clipboard by sending the keystroke combination Alt + EC (or whatever combination it uses) to your application.
However for this to work, your application window would need to have the input focus at the time.
The following console application uses this technique to read the currently selected text in a Notepad window which has to become the active window within 5 seconds of starting the application:
using System;
using System.Windows.Forms;
using System.Threading;
class Program
{
[STAThread]
static void Main()
{
Console.WriteLine("You have 5 seconds to switch focus to Notepad");
Thread.Sleep(5000);
SendKeys.SendWait("%EC");
string text = Clipboard.GetText();
Console.WriteLine(text + " is currently selected");
Console.ReadKey();
}
}