我基本上有这样一种情况,我需要从C#程序中获取富文本,将其复制到剪贴板中,然后使用pinvoke将其粘贴到另一个应用程序中。我知道如何获取必须粘贴的文本框的Handle
,但WM_PASTE
似乎没有按我的意愿行事。我花了一些时间在互联网上搜索,并且实际上发现了很多关于如何做到这一点的信息。
有人可以帮忙吗?我基本上有一个我需要粘贴的句柄IntPtr
。我需要将System.Windows.Forms.RichTextBox
中的富文本写入剪贴板,然后将其发送到其他程序的文本框。
这是我用来发送消息的pinvoke签名。
/// <summary>
/// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
/// <br />
/// To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.
/// </summary>
/// <param name="hWnd">
/// Handle to the window whose window procedure will receive the message.
/// If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
/// </param>
/// <param name="Msg">
/// [in] Specifies the message to be sent.
/// </param>
/// <param name="wParam">
/// [in] Specifies additional message-specific information.
/// </param>
/// <param name="lParam">
/// [in] Specifies additional message-specific information.
/// </param>
/// <returns>
/// The return value specifies the result of the message processing; it depends on the message sent.
/// </returns>
[DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto, SetLastError = false)]
internal static extern IntPtr SendMessageByString(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);
internal const int WM_SETTEXT = 0x000C;
我在接收聊天框句柄上调用SendMessageByString,但它似乎只采用纯文本。我需要将我的富文本放入剪贴板,然后进入聊天框。