|
-
Feb 17th, 2006, 03:04 PM
#1
Thread Starter
Fanatic Member
GetWindowText
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
-
Feb 17th, 2006, 04:34 PM
#2
Hyperactive Member
Re: GetWindowText
Have you tried making your own StreamWriter/StreamReader??
Here is an example
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....
Hope it helps...
-
Feb 17th, 2006, 04:44 PM
#3
Re: GetWindowText
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());
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Feb 19th, 2006, 04:41 PM
#4
Thread Starter
Fanatic Member
Re: GetWindowText
Thanks! I'm new to C#, I was trying to create a char array, and failed miserably. Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|