tags:

views:

514

answers:

3

This is a simplified version of what I am trying to implement to grab text from a mIRC chat window:

[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int msg, int wParam, StringBuilder sb);

public const int WM_GETTEXT = 0x000D; 

IntPtr mainHandle = FindWindow("mIRC", null);
IntPtr serverHandle = FindWindowEx(mainHandle, new IntPtr(0), "MDIClient", null);
IntPtr chanHandle = FindWindowEx(serverHandle, new IntPtr(0), "mIRC_Channel", null);
IntPtr staticHandle = FindWindowEx(chanHandle, new IntPtr(0), "Static", null);

int length = 50000;

StringBuilder sb = new StringBuilder(length + 1);
SendMessage(staticHandle, WM_GETTEXT, length + 1, sb);

textBox1.Text = sb.ToString();

However, this is not returning anything. It works for other windows, just not the Static window. Why? And please off any suggestions you may have for how I can read text from a mIRC window?

+1  A: 

You can communicate with mIRC using Windows DDE. You can read about it here. I'm not sure however if this will enable you to get the text.

shoosh
A: 

Are you sure the static really contains text and/or you have the correct static? If it's a static displaying an image for instance, you will not get the text (because there is no text to get) and SendMessage will return 0. See here.

Logan Capaldo
A: 

mIRC draws the contents of the chat window itself, that's why WM_GETTEXT won't work. You could write a proxy server and then change the mIRC settings to use your proxy server. That way you can capture the whole communication between mIRC and the IRC server.

Sofahamster