Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Here is my code:

C#
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

private const int WM_PASTE = 0x0302;

public void Paste()
        {
            Process proc = Process.GetCurrentProcess();
            SendMessage(proc.MainWindowHandle, (UInt32)WM_PASTE, (IntPtr)0, (IntPtr)0);
        }


The result is, well, nothing! Any advice?
Posted
Comments
yesotaso 10-Jun-11 8:21am    
See similar discussion:SendMessage API and WM_PASTE
[no name] 11-Jun-11 15:05pm    
If there is no receiver who handles the message, of course nothing happens..

0) Is the window you're sending the message to handling the WM_PASTE command?

1) Are you sure the clipboard contains an object that is compatible with the window in which you're pasting it?

2) Most of the time, only edit controls handle the WM_PASTE command. It looks like you're trying to make your main form do it (instead of an edit control IN the form).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Jun-11 19:12pm    
Correct, a 5. Besides, the whole idea is bad.
Please see my answer.
--SA
DominicZA 13-Jun-11 2:11am    
0) Not sure if the window is handling it! How can I check?

1) I am sure the clipboard contains text and I am trying to paste in notepad.

2) How do I access he edit control??
The typical window which supports WM_PASTE is some text-editing control or some image editing control, may be something else. It's virtually never a main window.

Besides, the whole idea is bad. You support good clipboard copy function, the user knows when to do the rest. If the application where you want to paste, this functionality is simply not needed. You need to integrate it in one application.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900