How would I get the text of a Window in C# via GetWindowText API, I can do this very easily in VB, but I can't seem to do it in C#.
Thanks,
Sir Loin
Printable View
How would I get the text of a Window in C# via GetWindowText API, I can do this very easily in VB, but I can't seem to do it in C#.
Thanks,
Sir Loin
Have you tried making your own StreamWriter/StreamReader??
Here is an exampleHope it helps...Code:static void Main(string[] args)
{
Console.WriteLine("***** Fun with streamwriters/ streamreaders****\n");
StreamWriter writer = new StreamWriter("reminders.txt");
.....
StreamReader sr = new StreamReader("reminders.txt");
}
// You will probably need to use the { get, set } that way you can specify the Window you want too read from....
but how will that help him to get the windowtext of an other open process? eg: an open instance of a program ( not a saved file on the hdd ) ;)
you want to be using the StringBuilder class as part of the GetWindowText Api.
eg:
VB Code:
[DllImport("user32.dll", EntryPoint="GetWindowTextA")] [COLOR=Blue]private static extern int [/COLOR] GetWindowText ([COLOR=Blue]int[/COLOR] hwnd, [COLOR=Blue][B]StringBuilder[/B][/COLOR] lpString, [COLOR=Blue]int[/COLOR] cch); [DllImport("user32.dll", EntryPoint="GetWindowTextLengthA")] [COLOR=Blue]private static extern int[/COLOR] GetWindowTextLength ([COLOR=Blue]int[/COLOR] hwnd); [COLOR=Green]/// in a function / void ...[/COLOR] StringBuilder sb = [COLOR=Blue]new[/COLOR] StringBuilder(); GetWindowText("handle to window", sb , GetWindowTextLength("handle to window")); Console.Writeline(sb.ToString());
Thanks! I'm new to C#, I was trying to create a char array, and failed miserably. Thanks again!