Can you control another program by using your own program? I'm not asking for specifics, just if it's possible or not?
Printable View
Can you control another program by using your own program? I'm not asking for specifics, just if it's possible or not?
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
well like controlling a tetris piece for example, could i do that?
Depends on what automation interfaces are exposed.....for a game I doubt it.......
ok, thank you
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....Quote:
Originally posted by Okiesmokie
Couldnt you do something like:
SendMessage(HWND of the window, WM_KEYDOWN, VK_LEFT, lParam);
?
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?..
Sending messages would be how a person controls a program.
>>> 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).
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
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.Code:if (bool whatever==1) {
//send message
}
so...
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.Code:int main() {
//send a command
//send another
//and so on
//and so forth
return 0;
}
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.
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?
>>>
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?
You wouldn't. You'd play like a human, move the mouse, and click.
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...Quote:
Originally posted by MrWizard
What if they are using Direct Input. It would not be as easy as "Sending Messages".
For me control is for stuff like Office Automation and the like