2

This is the method definition:

  [DllImport("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr lparam, IntPtr wparam);

This is the call to SendMessage:

 //WM_COPY = 0x0301
 SendMessage(handle, WM_COPY, IntPtr.Zero, IntPtr.Zero);

This is how I am retrieving the data:

string text = System.Windows.Forms.Clipboard.GetText();

I'd like to do the same thing except that I don't want the data to be copied to the clipboard. Is it possible to copy the data to some other part in memory? If so, how?

John Smith
  • 4,416
  • 7
  • 41
  • 56

2 Answers2

5

No. You can't control what other application will do when it receives a message. You get whatever behavior target window has for that message and nothing else (unless you control the target too, than you can handle it yourself).

WM_COPY is just a message (also it is standard one and make sense to be handled in particular way) - some windows will handle it, some will not. As defined on MSDN WM_COPY will save text for edit control.

An application sends the WM_COPY message to an edit control or combo box to copy the current selection to the clipboard in CF_TEXT format.

If you are implementing your own application that handles WM_COPY you can copy data wherever you want, also if sub-classing edit controls it would make a lot of sense to keep default behavior...

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • That makes sense. The problem is that I am trying to copy data from a RichTextControl (http://msdn.microsoft.com/en-us/library/windows/desktop/bb787605%28v=vs.85%29.aspx) but when I send it a message using EM_STREAMOUT, I get a bunch of metadata indicating that the item in question is an image, not text. (That might explain why you can't select the text one character at a time.) However, when you send it the WM_COPY message it does return the associated text. My goal is to retrieve that text without having to rely on the clipboard – John Smith Nov 26 '12 at 17:26
  • @JohnSmith, I don't know. You should ask separate question on what you actually want (don't forget to add info on what you tried) as this one is very narrow and likely you need to use some other massage/helper methods. – Alexei Levenkov Nov 26 '12 at 17:31
0

You could write it to a file instead if the clipboard is not an option.

gaynorvader
  • 2,619
  • 3
  • 18
  • 32
  • Not sure what you suggest... It looks like John Smith wants some other window/application to behave differently when handling WM_COPY.. – Alexei Levenkov Nov 26 '12 at 17:12