Control Another Application Using C#

Control another application using C#

Have you looked at White TestStack?

Sample code:

Application application = Application.Launch("foo.exe");
Window window = application.GetWindow("bar", InitializeOption.NoCache);

Button button = window.Get<Button>("save");
button.Click();

I don't think it can get better than that. The library is created by ThoughtWorks.

C# application to control another application

SendMessage and SendWait will always have those sorts of issues (especially app-to-app), e.g. the user clicks someone on the screen at exactly the right/wrong time. Really the only way I know to reliably do this is by hooking onto the mouse/keyboard and take total control... its hard and painful.

Note: there are plenty of professional macro'ing software packages on the market (faking keyboard input, mouse movement, clicks etc). Some are very sophisticated with their own programming language and will possibly do what you want. Google "windows macroing software" and you will find heaps - I recommend you do you research, trial several packages til you find one you want and then purchase it.

Control another Program with C#

Autoit

With Autoit you can record macro or program to automate other programs

Interact with another program with C#

I just want to say that what you are doing is going to be pretty tough to make reliable without cooperation from the developers of the other applications. However, you can use Windows Messages to accomplish what you're trying to do. This is a way to send information to a window without explicit communications being set up. You'll need to use native methods to do this, but it's pretty straightforward. Be careful, however, as implementing this is not as trivial as it looks - you can get into deadlocks if you accidentally send a message to a closed (or invisible) window, for example.

This is too big a topic for a Stack Overflow post, but here are some relevant functions to get you started:

PostMessage and SendMessage are the main functions you can use to send messages to other applications.

The answers to this post have some basic examples of how to use these functions.

Finally, here is a list of Windows message codes for reference.

Find control of specific class in another application

Thanks for the answer above. It's very detailed. I ended up using a more simple approach:

 private IntPtr FindHandle()
{
while (true)
{
IntPtr handle = FindWindowEx(this.ApplicationHandle,IntPtr.Zero,"TRichEdit", null);
if (handle == null)
{
throw new Exception("No handle found");
}
if (handle != this.Handle_01)
{
return handle;
}
}
}


Related Topics



Leave a reply



Submit