开发者

How can one control third party app which has no API? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_开发问答

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 7 years ago.

Improve this question

I need to control some third party app which has no API and very limited command line arguments. So I need to simulate user interaction using .net and C#.

What I need to do:

  • start the application (this works)
  • enter string into appropriate edit fields
  • press button
  • extra bonus is to hide app window

Can this be done and how ?

Thank you very much.


EDIT: What do you think about AutoIt tool ?


You could achieve this using White.

It enables you to programmatically simulate user interaction with Win32, WinForms, WPF, Silverlight and SWT applications. I used it years ago when it first can out to automate some simple smoke tests on a WinForms application with great success.

(Caveat: this is based on my usage a while ago, so it may be slightly different now)

I created some code to launch my application and find a series of controls by name. Once found, each control could be manipulated (e.g. text entered, button clicked, etc...). To find the name of the controls, use something like Spy++ (Win32), UISpy (WinForms) or Snoop (WPF) to inspect the running application.


Theres also the UI Automation API, which, for this task, would be pretty easy to whip up. This link will give you an idea of the support for each of the control types:UI Automation Control Types. You can use the control name, caption or resource ID in order to grab its handle, and do what you want. Clicking a button can be as simple as grabbing the handle and:

AutomationElement control = AutomationElement.FromHandle(controlHandle);
InvokePattern ip = (InvokePattern)control.GetCurrentPattern(InvokePattern.Pattern);
ip.Invoke();

I've had very good success with this on all .net windows, and 99% of controls from the native world

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜