Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I'm trying to send text from my application to some 3rd party application and it's not happening.
With my application I'me able to send to Notepad and other text editor software but not to all the application.



Can anyone help me to fix this issue.
Any suggestion are welcome.

Regards,
Dom

What I have tried:

Here is my code snippet:
C#
Process[] notepads = Process.GetProcessesByName("notepad");
if (notepads.Length == 0) return;
if (notepads[0] != null)
{
    IntPtr child = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);

    System.Threading.Thread.Sleep(2500);
    
    SendKeys.Send("Hi");
   
}
Posted
Updated 14-May-20 3:39am
v3
Comments
Richard MacCutchan 14-May-20 4:48am    
Your question is unclear. What is that code supposed to do, and what is the actual error? What is the 3rd party app that you send messages to?
Richard MacCutchan 14-May-20 10:34am    
Well you have changed the code in your question, but you have still not explained what the problem is.
Dave Kreskowiak 14-May-20 13:15pm    
You do realize that the Process class you get back has a MainWindowHandle property for the app, right? That makes the Win32 call to FindWindowEx a moot point.

Also, the code you posted gets the window handle, but you never do anything with it. The call to FindWindowEx does NOT activate the window, so SendKeys is going to just type into whatever window has the focus.

Really, using SendKeys at all is a horrible idea.
domneck 15-May-20 0:27am    
Yes I agree, SendKeys is going to just type into whatever window has the focus. This is still fine for me.
But it's not working for 3rd party application is there any alternative for this.
Dave Kreskowiak 15-May-20 9:33am    
You have to activate the target window to get it the focus before SendKeys is going to do anything.

Keep in mind, SendKeys is so bad because the user can switch the active window any time they want, and there's nothing your code can do to prevent it.

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