如何在C#/ Win32中编写和发送文本到mIRC?

时间:2009-02-07 12:14:49

标签: c# winapi irc

在上一个问题中,我问how to send text to Notepad。它帮了我很大的忙。对于第2部分,这是相同应用的mIRC的简化版本:

[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), "Edit", null);

SendMessage(editHandle, 0x000C, 0, textBox1.Text);

这对我来说似乎是正确的,除了它不起作用!是否窗口名称不正确(MDIClient,mIRC_Channel和Edit)?这些是我通过Google搜索“FindWindowEx mIRC”在网站上找到的值。

1。)上面我做错了什么?

2。)作为参考,一般来说,有一种简单的方法可以找到与FindWindowEx()一起使用的所有窗口名称吗?

1 个答案:

答案 0 :(得分:4)

此代码适用于我(mirc 6.31):

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, 0x000C, 0, "Hello World");

注意更改的窗口类(richedit20A而不是edit)。刚刚使用Spy ++找到了正确的类。

对于窗口句柄,一种可能是使用EnumWindowsEnumChildWindows API。