controling another program

This is a discussion on controling another program within the Windows Programming forums, part of the Platform Specific Boards category; Can you control another program by using your own program? I'm not asking for specifics, just if it's possible or ...

  1. #1
    Unregistered
    Guest

    controling another program

    Can you control another program by using your own program? I'm not asking for specifics, just if it's possible or not?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Depends on the program and depends on what you mean by control....

    You can start/terminate programs easily, but if you want to be able to automate stull like opening documents, formatting output etc... (just like you can with M$ Office programs via VBA) then it will depend on what facilities that program provides for you.....

    Most programs allow themselves to be controlled by exposing COM interfaces so they can be scripted by languages like VBScript and VBA

  3. #3
    Unregistered
    Guest
    well like controlling a tetris piece for example, could i do that?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Depends on what automation interfaces are exposed.....for a game I doubt it.......

  5. #5
    Unregistered
    Guest
    ok, thank you

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Couldnt you do something like:

    SendMessage(HWND of the window, WM_KEYDOWN, VK_LEFT, lParam);
    ?
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Okiesmokie
    Couldnt you do something like:

    SendMessage(HWND of the window, WM_KEYDOWN, VK_LEFT, lParam);
    ?
    Yes but simply sending mesages wont properly control a program....

    Can you imagine opening a word doc........then having it mail merge with an access database, save the document and then print it all just by sending messages?..

  8. #8
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Sending messages would be how a person controls a program.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> Sending messages would be how a person controls a program.

    Of course, but how would you know what messages to send and when? Unless you had the command sequences of the target program, you would have to rely on a published API, (not for a game I suspect), or an interface, which brings us back to imbedding/COM, (also unlikely for a simple game).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    depending on whats going on, there are a number of ways to send it messages, such as the timeout function often used in splash screens. Depending on how you want your program automated,: create a timer function, then when the timer finishes have it set a value to a bool. after that, in a new function
    Code:
    if (bool whatever==1) {
    //send message
    }
    that will pretty much automate it...however if you're looking to create a program that just automates another (you don't seem to be looking for users to issue the commands) just use a DOS console, much easier to use because it is not event driven like windows programming, it pretty much runs through the code systematically. So, include windows.h and you can send messages to other windows via the normal commands.
    so...
    Code:
    int main() {
    //send a command
    //send another
    //and so on
    //and so forth
    return 0;
    }
    it will run through the code without waiting for user prompts...and if you're using it with a tetris game...you can use user events there to do shellExecute() your DOS program, which will run a bunch of commands to control your tetris game.
    Of course I don't know exactly what you're doing, but that's as good of an example I can come up with from what you've typed on the board.
    good luck.
    Last edited by Waldo2k2; 06-16-2002 at 02:53 PM.
    PHP and XML
    Let's talk about SAX

  11. #11
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    But he was talking about a game, therefor if u send the WM_KEYDOWN message with VK_LEFT, you would move the character or whatever to the left, wouldnt u?
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  12. #12
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>>
    therefor if u send the WM_KEYDOWN message with VK_LEFT, you would move the character or whatever to the left, wouldnt u?
    <<<

    Thuis may work for a simple program, (unless the target is looking for WM_KEYUP of course - common strategy), but how would you start a more sophisticated program? How would you know what values he is expecting from his menu commands for example?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  13. #13
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    You wouldn't. You'd play like a human, move the mouse, and click.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What if they are using Direct Input. It would not be as easy as "Sending Messages".
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  15. #15
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by MrWizard
    What if they are using Direct Input. It would not be as easy as "Sending Messages".
    Exactly........Simply sending messages will not give you any real control....if you are happy simulating keystrokes and mouse messages and labeling it "control"...well fair enough...

    For me control is for stuff like Office Automation and the like

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21