Link to home
Start Free TrialLog in
Avatar of ttobin333
ttobin333

asked on

How to paste clipboard without using keyboard simulation/send keys

I need to paste the clipboard (text) contents into other windows and will assign keyboard shortcuts to these commands, so I do not want to use various key sending methods, as these complicate the matter.

How can I send the clipboard to the last cursor location before my program's window became active?

Thanks for your help!
Avatar of SStory
SStory
Flag of United States of America image

hmm. You could send a window message using SendMessage() API call--given that you have a handle to the other window.

More on SendWindow()
http://msdn2.microsoft.com/en-us/library/ms644950.aspx

Some apps use a EM_PASTE, but I don't think that is guaranteed for all apps, and this would only work for textboxes probably.  You could send a WM_CHAR or something with Ctrl+V  (you said you didn't want to do this).

Apart from this I know of no way to do it.
Avatar of ttobin333
ttobin333

ASKER

Thanks. How can I get the handle of the window that was active just before my application became the active window?
Here are some ideas about that:
http://forum.sysinternals.com/forum_posts.asp?TID=10793

It seems that you have to trap and handle WM_ACTIVATEAPP message in your app and possibly call GetForegroundWindow()  Also some suggest playing with the Z-ORDER.  none of these seem real simple.

HTH,

Shane
Thanks Shane.

I was able to obtain the handle of the last active window. Now can you assist with the implementation of the SendMessage API call for pasting the clipboard contents without using keyboard commands?

Is the handle of the target window sufficient, or do I need the handle of the control (e.g. textbox) to be able to do this?

Tobin
ASKER CERTIFIED SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Getting the handle of the window is one thing, getting the handle of the control (textbox or other) is another...can you tell me how to do this?

Is there some way to just past at the last cursor location of the window?

Thanks!
Here's some code on doing that:

http://cuinl.tripod.com/Tips/wincaption.htm

Does this help?

I'm not sure it will get the child window though.
Also there is a Spy+ or Spy++ or something like that, that was a tool with Visual C++.  You can move the cursor over the top of a window to discover the classname of a child control.
Here is an old article on doing this also:
http://www.microsoft.com/msj/0397/Win32/Win320397.aspx
Sorry,  this is not working out...

To summarize, I just want to paste text from the windows clipboard into the last cursor location of another window (that I have the handle of). My program is the active window, and this action will be initiated by a command button.

Something as simple as pasting text should not be so complicated, but I guess it is. Any other suggestions?
I would have thought, make your window not visible, grab the active window hWnd then make yours visible again.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial