Changing an Effect

You can modify the parameters of an effect, in some cases even while the effect is playing. You do this by using the IDirectInputEffect::SetParameters method.

The dwDynamicParams member of the DIEFFECTINFO structure tells you which effect parameters can be changed while an effect is playing. If you attempt to modify an effect parameter that cannot be modified while the effect is playing, and the effect is still playing, then DirectInput will normally stop the effect, update the parameters, and restart the effect. You can override this default behavior by passing the DIEP_NORESTART flag.

The following C++ example changes the magnitude of the constant force that was set in the example under Creating an Effect.

DIEFFECT        diEffect;           // parameters for effect
DICONSTANTFORCE diConstantForce;    
  // type-specific parameters.

diConstantForce.lMagnitude = 5000;
diEffect.dwSize = sizeof(DIEFFECT); 
diEffect.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); 
diEffect.lpvTypeSpecificParams = &diConstantForce;
hr = lpdiEffect->SetParameters(&diEffect, DIEP_TYPESPECIFICPARAMS);
 

The flag ensures that the transfer of data from the DIEFFECT structure is restricted to the relevant members, so that you do not have to initialize the entire structure and so that the minimum possible amount of data needs to be sent to the device.