【发布时间】:2017-02-22 21:26:04
【问题描述】:
当我尝试将文本从我的 RichTextBox 发送到 Notepad++ 时,它只发送文本的第一个字母。因此,如果我在 Notepad++ 中的文本框中有 Send this to Notepad++,那么所有会显示的是 S。
这是我的代码
[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);
private void button2_Click(object sender, EventArgs e)
{
Process[] notepads = Process.GetProcessesByName("notepad++");
if (notepads.Length == 0) return;
if (notepads[0] != null)
{
IntPtr child = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Scintilla", null);
SendMessage(child, 0x000C, 0, RichTextBox1.Text);
}
}
【问题讨论】:
-
CharSet = CharSet.Unicode。标准建议:使用 UI 自动化来避免弄错这些细节。 System.Windows.Automation 命名空间。
标签: c# sendmessage