简体   繁体   中英

How Can I control another programs?

my question is general for all languages, but I'm using only C, so, I would like to get answer in this one.

My question is, How Can I control the behavior of another applications that I didn't write?

For example:

  • How Can I fill this entry box (in this site) using C? Do I need to control the browser? (I'm using firefox.)

  • Still in this example, How Can I open another tab in this browser using C? (see, I want to control this
    application such another one)

  • How Can I embed a program im my one?

  • How Can I fill a database program using your gui, doing it by c?

and so on...

Thanks a lot!

There's no concrete or single answer to your (multiple) questions because every program varies. Short of the desired application having an API, you can resort to using low level Win32 commands to identify handles of processes and windows within those processes which you want to change/read. It's by no means a straightforward or scalable process though.

您必须与该程序API进行交互。

Some programs are scriptable and publish APIs that allow other programs to send commands to them. If your "target" app does something like this, then that will typically be your best bet.

If the app doesn't have a C API, then you probably can't control it in C. That doesn't mean it's impossible, only that you might need a different language. If your app is a Windows GUI app, you can use AutoIt to interact with the GUI programmatically.

Typically you use a program's application programming interface (API) to gain access to publicly available functions that let you accomplish tasks within that program. However, not every application has an API that you can use.

You should start by looking at the documentation of the application you're intending to take control of with your program and seeing if they have an API suitable for your needs.

Most of the time application need API to work with each other. There is another way around to automatise actions done to applications (like an user would). For example on Windows there is an "language" named AutoIt which can interact with your computer.

I'm not really sure if this is what your seeking but it can do almost all the thing you asked for.

question is, How Can I control the behavior of another applications that I didn't write

Answer: that depends on the application and platform (linux, windows, mac, ...). It generally does not depend on your language of choice.

As an example, quite a lot of gtk/ kde programs on linux can be partially controlled via the dbus messaging bus. Those apps are designed to be controlled in that way.

I think firefox has a command line option to open a new website using an already running browser.

Applescript or automator on a mac can be used to control some apps too, I believe.

In short, make a separate question on what you want to do exactly , stating both platform and app you need to control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM