Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application which copies the Email Id to clipboard in my application. What i want to next is, When the user clicks on the text box of the Browser(IE,Chrome,FF) And presses the paste button of my application , it should paste the contents of the clipboard in that focused TextBox. Please Note that my Application is Created in MFC, c++. I have Implemented code for copying the text to clipboard from within my application, but am wondering how will it be possible to paste the text outside my application , when the event is fired from my application. If question is not clear please comment it. Your Help will be highly appreciated. Thanks In Advance.
Posted
Comments
Jochen Arndt 14-Nov-13 3:20am    
Think about it:
When clicking on the text box of the browser, the browser becomes the active app and the text box has the focus. When now clicking a button of your app, your app becomes the active app. But your app can't know which app was active before and which element in that app had the focus.

The only solution for such a problem would be to use an app that provides some kind of controlling interface like COM.

A better solution would be to use Drag&Drop: Just drag the selected text to the text box.

1 solution

This should be possible using window hooks, and especially CBTProc. Here are the docs from MS: CBTProc callback function[^]

It might not be possible for clients which don't use GDI(+) to draw their windows (which might be true for WPF based applications, but i honestly don't know), but let's say, every application whose windows show up in a tool like SPY++ (which is part of the Microsoft Visual Studio Installation) should be able to be tracked using the hook.

There are several articles about hooking available on the web and also on codeproject itself. Maybe there's even one which comes close to what you're looking for. For example, have a look at this one: Manipulating Windows using messages and simple CBT hooking[^]

Using this hook, it is possible to track the active application from within another application. What's then left to do is to find a way to put the desired text into the target control. There exist several not too difficult possibilities to approach that. I haven't tested it, but using WM_SETTEXT instead of get like described here[^] could do the trick.

Here's an excerpt from SPY++ 64bit for an IE8 64bit instance where IEs main window handle is 001C1BBC and the one from the address combobox 00091C20.

<00069> 001C1BBC S WM_ACTIVATEAPP fActive:True dwThreadID:00000000
<00070> 001C1BBC R WM_ACTIVATEAPP
<00071> 001C1BBC S WM_NCACTIVATE fActive:True
<00072> 001C1BBC R WM_NCACTIVATE
<00073> 001C1BBC S WM_ACTIVATE fActive:WA_CLICKACTIVE fMinimized:False hwndPrevious:(null)
<00074> 001C1BBC R WM_ACTIVATE
<00075> 001C1BBC S WM_GETICON nType:ICON_SMALL
<00076> 001C1BBC R WM_GETICON hicon:7D9016F5
<00077> 001C1BBC S WM_SETCURSOR hwnd:00091C20 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<00078> 001C1BBC R WM_SETCURSOR fHaltProcessing:False
<00079> 001C1BBC S WM_SETCURSOR hwnd:001C1BBC nHittest:HTCAPTION wMouseMsg:WM_MOUSEMOVE
<00080> 001C1BBC R WM_SETCURSOR fHaltProcessing:False
<00081> 001C1BBC P WM_NCMOUSEMOVE nHittest:HTCAPTION xPos:725 yPos:47
<00082> 001C1BBC S WM_SETCURSOR hwnd:001C1BBC nHittest:HTCAPTION wMouseMsg:WM_MOUSEMOVE
<00083> 001C1BBC R WM_SETCURSOR fHaltProcessing:False
<00084> 001C1BBC P WM_NCMOUSEMOVE nHittest:HTCAPTION xPos:751 yPos:33
<00085> 001C1BBC P WM_NCMOUSELEAVE
 
Share this answer
 
v3

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