-4

The original code i posted has been edited, as it seems it caused confusion. I know it was wrong but i only wanted to use it as an example. Code i want to work with is this one:

https://github.com/SFML/SFML/wiki/Source:-AnimatedSprite

You can just focus on this part:

while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
        }

        sf::Time frameTime = frameClock.restart();

        // if a key was pressed set the correct animation and move correctly
        sf::Vector2f movement(0.f, 0.f);
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            currentAnimation = &walkingAnimationUp;
            movement.y -= speed;
            noKeyWasPressed = false;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            currentAnimation = &walkingAnimationDown;
            movement.y += speed;
            noKeyWasPressed = false;
        }

Let´s assume that instead of

 if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))

i want this program to act from parameters received from outside this code.

This would be the scheme i want to follow:

From my C++ code (let´s call it Origin) i call this programme (lets call it AnimatedSprite.exe) with this command:

 ShellExecute(NULL,NULL,"C:\\AnimatedSprite.exe",NULL ,NULL,SW_SHOWDEFAULT);

This will open the AnimatedSprite.exe without sending any command.

Now i want to keep it open and send him commands, like

ShellExecute(NULL,NULL,"C:\\Try.exe",MyCommandLetter.c_str() ,NULL,SW_SHOWDEFAULT);

So that when my already opened AnimatedSprite.exe receives "MyCommandLetter" as argv (yes, i know i have to declare argc and argv in main, i have to modify the original code)

it does something like:

if (argv[1]=='a')
{
currentAnimation = &walkingAnimationUp;
                movement.y -= speed;
               noKeyWasPressed = false;
}

Hope it got more clear.

It does not matter if i have to use other function which is not ShellExecute, as long as i can understand how it works (with this example it would be OK).

Thanks in advance.

Maiser
  • 65
  • 1
  • 10

1 Answers1

0

Ok, as I understand the question, you want the called program react on multiple arguments. In that case you should build your main not as single "if else" statement, but rather a loop over arguments with "switch case" statement, processing all given arguments. Look for example here