tags:

views:

50

answers:

0

I basically have a situation where I need to get rich text out of a C# program, copy it into the Clip Board, and Paste it into another Application using pinvoke. I know how to get the Handle of the Text Box it has to be pasted into, but WM_PASTE doesn't seem to do what I want. I have spent some time searching around the internet, and am having a great deal of trouble actually finding much information about how to do this.

Can anyone assist? I basically have the handle I need to paste into as an IntPtr. I need to get the rich text from a System.Windows.Forms.RichTextBox into the clipboard, and send it to the other program's text box.

This is the pinvoke signature I am using to send the message.

    /// <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;

I am calling SendMessageByString on the receiving chat box handle, but it only seems to take plain text. I need to get my rich text into the clipboard, and then into the chatbox.