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