How Can I control another programs? - c

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.

You'd have to interact with that programs 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.

Related

Cocoa UI on terminal app

I've been tasked to build a Cocoa interface for a C terminal application.
There are no requirments other than the GUI.
My question is:
Would it be best and/or fastest to make the terminal calls or get source code (which I do have authorization to use) and call the functions directly from Cocoa?
Please state pros and cons for educational purposes.
It would be best (faster, easier) to call the functions directly from Cocoa.
Of course you realise that Cocoa apps must be Sandboxed if they are going on the Mac App Store and Sandboxing can make many, previously trivial, operations much more complicated?

How to write an application that uses the terminal as GUI? (in C)

I'd like to write an application (in C) that uses the terminal of a *nix OS as its GUI. I mean an application of the kinds of emacs, vi etc. that take up the whole terminal window and jump back to the input prompt after quitting.
How would you go about doing that, preferably in C? Can someone point me to a tutorial covering that?
You need to use ncurses:
http://en.wikipedia.org/wiki/Ncurses
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
It is available on all major distros.
Well, actually this is not GUI (graphic user interface) but a text based interface. You can use the library ncurses to create such applications in C.
Use a library like ncurses, it is specifically designed for this purpose.
Throwing in alternate solutions so that this question thread does not look so monotonic:
the slang library (mc uses it, for example)

How to minimize to system tray in C

How can I minimize my app to the system tray as soon as it starts in C?
I am new to C.
Thanks.
Are you talking about Windows and the taskbar status area? If so, check http://msdn.microsoft.com/en-us/library/windows/desktop/bb762159.aspx for the Shell_NotifyIcon function. There are plenty of references, and even some samples linked on how to use it.
Also Notifications and the Notification Area: http://msdn.microsoft.com/en-us/library/windows/desktop/ee330740.aspx
C, all by itself, is not capable of doing what you want. The language was designed to work on as many possible architectures as possible (microwave ovens ... air bag systems ... mouse movement control ...) and not all such architectures know what a "system tray" is.
You need to use specific libraries (which augment the capabilities of Standard C). There are lots and lots (and lots) of external libraries. Most libraries to do the same thing on different platforms are not compatible between each other ... so we need to know what is the target of your code: Windows? Windows Vista? DOS? microwave oven? sattelite solar panel deployer? ... :-)
Create a window but don't show it.
Use Shell_NotifyIcon to create the icon in the notification area.
In order to perform step 2 you will need the window created in step 1.
If you have never programmed in C before and never used the Win32 API before this is an ambitious first project. First of all you should master the basics of showing windows, programming a message loop, handling messages etc. I recommend Programming Windows by Petzold.

OS independent clipboard copy/paste text in C

I'm working on a project that's supposed to work on both Windows and Linux (with an unofficial Mac port as well) that emulates a true colour system console.
My problem is that recently there appeared a request for textfield support (yes, console-based) and it would be cool to add the possibility of copying text to clipboard and pasting from it. Is there a way of achieving this that will:
be done in C (not C++),
work in both Windows and in Linux (preprocessor macros are an option if there's no platform-independent code),
require no extra libraries to link to?
Thanks in advance for your help.
If you're not using a cross platform UI library (like wx or something), then it sounds like you're just going to have to write native clipboard code for each platform you want to support.
Remember, on Macintoshes, you copy with Command-C, not Ctrl+C :)
The clipboard is inherently an operating system defined concept. The C language itself has no knowledge of what a clipboard is or how to operate on it. You must either interface directly with the OS, or use a portability library that does this on your behalf. There is no way around this.
Personally I would define my your own function
getClipboardText();
That is defined in two different header files (linux_clipboard.h, windows_clipboard.h, etc) and then do pre-proccessor stuff to load the appropriate one accordingly. I don't really code in C/C++ so I'm sorry if that didn't make any sense or is bad practice but that's how I'd go about doing this.
#if WIN32
#include windows_clipboard.h
#endif
That sort of thing
Remember:
For linux you have to deal with different window managers (Gnome, KDE) all with different ways of managing the clipboard. Keep this in mind when designing your app.
You may be able to communicate to the clipboard by using xclip. You can use this python script here to do this job via communicating with 'dcop' and 'klipper' here. That is for KDE, I do not know how it would be done under GNOME... You may also be able to do this independantly of either GNOME/KDE by using DBUS, although I cannot say 100% confidently on that either...
Just be aware, that for a truly cross-platform job, you have to take into account of the different GUI's such as under Linux, X is the main window manager interface and either GNOME/KDE sits on top of it..I am not singling out other GUI's such as FluxBox, WindowMaker to name but a few, and that there will be a lot of platform dependant code, and also in conjunction, you will be dealing with Windows clipboard as well..all in all, a big integrated code...
Have you not considered looking at the raw X programming API for clipboard support? Maybe that might be better as I would imagine, GNOME/KDE etc are using the X's API to do the clipboard work...if that is confirmed, then the work would be cut out and be independant of the major GUI interfaces...(I hope that would be the case as it would make life easier for your project!)
Perhaps using compile-time switches, for each platform...WIN, KDE, GNOME, MAC or use the one that is already pre-defined..
Hope this helps,
Best regards,
Tom.

Good portable wiimote library with sound support?

I'm lookin for a portable wiimote library. I want to use the wiimote for the hardware it has (but I don't need to access any data stored on it).
Required features:
access to all the buttons (as an exception, no use of the power button is OK)
make the wiimote play sound
talk to nunchuks and classic controllers
preferably: make the wiimote rumble.
interface with C. Preferably native C. Bonus points for bindings with Haskell or python.
The library should port to Linux, Windows and OS X (in order of importance) and should be agnostic with respect to CPU architecture.
Anyone got a good suggestion?
Haven't use it (I've only read about the managed Wiimote library really), but you may want to check out wiiuse. It seems like the most complete of the native libararies.
Others include:
GlovePIE
WiiYourself
You can use my WiiMouse program to do this (which is based on the wiimotelib open source project), it allows you to connect via named pipes and play PCM sounds and use all the attachments including the MotionPlus, it even calculates the MotionPLus vectors for you, you can get it here:
http://home.exetel.com.au/amurgshere/wiimouse.phtml
See the download for an example on how to connect to a wiimote via named pipes and play sounds and stuff.

Resources