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

发布于 2024-07-13 06:36:37 字数 1187 浏览 7 评论 0原文

在上一个问题中,我问如何将文本发送到记事本< /a>. 这对我帮助很大。 对于第 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)? 这些是我通过谷歌搜索“FindWindowEx mIRC”在网站上找到的值。

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

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

In a previous question, I asked how to send text to Notepad. It helped me immensely. For part 2, here's a simplified version of the same applied 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);

This seems correct to me, except that it doesn't work! Is it that the window names are incorrect (MDIClient, mIRC_Channel, and Edit)? These are values I found on a web site by googling "FindWindowEx mIRC".

1.) What am I doing wrong in the above?

2.) For reference, in general is there an easy way to find all the Window names for use with FindWindowEx()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭了丶谁疼 2024-07-20 06:36:37

此代码适用于我(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 而不是编辑)。 刚刚使用 Spy++ 找到了正确的类。

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

This code works for me (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");

Notice the changed window class (richedit20A instead of edit). Just found the correct class by using Spy++.

As for the window handles, one possibility is to use the EnumWindows or EnumChildWindows API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文