tags:

views:

301

answers:

0

I' found some code to send messages to irc, but i can't get it to send it to the server aswell. Here is the code:

[DllImport("User32.dll", EntryPoint = "FindWindow" )]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

[DllImport("user32.dll", EntryPoint = "FindWindowEx" )]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.dll" )]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

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 editHandle = FindWindowEx(chanHandle, new IntPtr(0), "RichEdit20A", null);

SendMessage(editHandle, 12, 1, text); //send text to active channel edit box.

if (autoSend)

SendMessage(editHandle, 258, 13, text); //press enter. 13 = enter 258 = VM_CHAR

This works if the program is visible on screen or in taskbar, it seems to remove the text and then press enter if the program is minimized to the tray, tried using VM_KEYDOWN but didn't work either, any help is appreciated!