Get the selected Text from other Process

M

Marcus Peters

Hi folks,

I need to copy the selected text in any other application to the clipborad.

I played around with several ways which did not work:

Win API: Send a Message with WM_COPY --> Worked only with TextBoxes,
ComboBoxes and so on, There are several posts for doing so.
But way to copy from for example from IE.

Win API: Send some Messages wich should simulate pressing the Ctrl-C keys
(SendMessage and keybd_event)
Any Ideas ?



Regards,

Marcus
 
M

Marcus Peters

Hi Mohamed,

thanks for your help. But that was not what I was looking for.
I managed it by my self now.

My Question was to Send Ctrl-C to a window of any other process. This is to
tell
windows I wanna copy the selected text of the particular window. I need to
send Ctrl-C
cause the window may contains control other than Textbox or ComboBox (wich
accept the WM_COPY Message).

But as I told you I made it. If you need help doing the same let me now I
will tell you then.

Best regards,

Marcus
 
M

Mohamoss

HI Marcus
thaks for the reply , yes sure please share that so any one would make use
of it while encountraing the same situation
thanks again
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
M

Marcus Peters

Hi Mohammed,

here is the code

....
[DllImport("User32.dll")] private static extern bool

SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll", CharSet=CharSet.Auto)]

static public extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]

static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,

uint dwExtraInfo);



.....

private void SendCtrlC(IntPtr hWnd)

{

uint KEYEVENTF_KEYUP = 2;

byte VK_CONTROL = 0x11;


SetForegroundWindow(hWnd);


keybd_event(VK_CONTROL,0,0,0);

keybd_event (0x43, 0, 0, 0 ); //Send the C key (43 is "C")

keybd_event (0x43, 0, KEYEVENTF_KEYUP, 0);

keybd_event (VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up



}


Regards,

Marcus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top