Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,129 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,009 people online right now. Registration is fast and FREE... Join Now!




Scraping the text from another application with win32 api

 
Reply to this topicStart new topic

Scraping the text from another application with win32 api, the window is non-standard, so getwindowtext isn't working!

nightmares
post 4 Oct, 2008 - 10:48 PM
Post #1


New D.I.C Head

*
Joined: 4 Oct, 2008
Posts: 1

Hey Everyone

I'm writing an application, and part of it includes scraping the text from a chat box in another application currently running on the computer. So, if the chat box in another running program contains something like
Me: Hi
You: Hi
Me: lol
I want to get "Me: Hi You: Hi Me: lol" into a string variable in my application so that I can parse it as needed. I have tried using some win32 api calls as follows:

CODE

            IntPtr handle = new IntPtr(11111); //note: i can get the window handle, this isn't the issue
            int nChars = GetWindowTextLength(handle); //win32 function
            StringBuilder Buff = new StringBuilder(nChars);

            if (GetWindowText(handle, Buff, nChars) > 0)  //also win32 function
            {
                Console.WriteLine(Buff.ToString());
                Console.WriteLine(handle.ToString());
            }
            else
            {
                Console.WriteLine("fail");
            }


I also tried:

CODE


            IntPtr window_hwnd = 313312; //I can find the window handle, this isn't the problem
            Int32 txtlen;

            txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero);

            if (txtlen == 0)

                return "";



            txtlen = txtlen + 1;

            StringBuilder txt = new StringBuilder(txtlen);

            SendMessage(window_hwnd, WM_GETTEXT, txtlen, txt);

            Console.WriteLine(txt.ToString());


Note that above these code fragments are all of the dllimports for the windows functions. Also, the code fragments work for other windows programs, like notepad. From what I understand, GetWindowText and sending a WM_GETTEXT message only work if the target window is a standard windows control. Because they aren't returning anything when I know there is text in the chat window, I have concluded that the chat window is not a standard windows control. Does anyone know how to get the text out of a non-standard windows control? Note: I'm trying to use the windows api but if I can't, that's ok.

Thanks for any comments/suggestions smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 11:49AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month