Get the selected Text from other Process

  • Thread starter Thread starter Marcus Peters
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top