Results 1 to 4 of 4

Thread: GetWindowText

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    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

  2. #2
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    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...

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    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:
    1. [DllImport("user32.dll", EntryPoint="GetWindowTextA")]
    2. [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);
    3.  
    4. [DllImport("user32.dll", EntryPoint="GetWindowTextLengthA")]
    5. [COLOR=Blue]private static extern int[/COLOR] GetWindowTextLength ([COLOR=Blue]int[/COLOR] hwnd);
    6.  
    7. [COLOR=Green]/// in a function / void ...[/COLOR]
    8. StringBuilder sb = [COLOR=Blue]new[/COLOR] StringBuilder();
    9.  
    10. GetWindowText("handle to window", sb , GetWindowTextLength("handle to window"));
    11.  
    12. 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]

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    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
  •  



Click Here to Expand Forum to Full Width