PlaySound

サウンドファイルを再生します。

bool  PlaySound(
  string  filename      // ファイル名
  );

パラメータ

filename

[in]  サウンドファイルへのパスファイル名が NULL の場合は、再生が停止されます。

戻り値

ファイルが見つかった場合は true、それ以外の場合は false

注意事項

ファイルは terminal_directory\Sounds またはそのサブディレクトリに位置しなければいけません。WAVファイルのみが再生されます。

PlaySound() の NULL パラメータでの呼び出しは、再生を停止します。

PlaySound() 関数はストラテジーテスター内では使用できません。

Example:

#include <Trade\Trade.mqh>
#define MAGIC (123)
 
//--- input parameters
input string         InpFileNameOK  = "ok.wav";               // success audio file
input string         InpFileNameErr = "timeout.wav";         // error audio file
input ENUM_ORDER_TYPE InpOrderType   = ORDER_TYPE_BUY_LIMIT;   // order type
input double         InpLots        = 0.1;                   // lots
 
//--- global variables
CTrade ExtTrade;
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
//--- set the magic and order type by execution according to the symbol settings
  ExtTrade.SetExpertMagicNumber(MAGIC);
  ExtTrade.SetTypeFillingBySymbol(Symbol());
//--- call the function of placing an order or opening a position with sound playback
  OrderSendWithAudio();
 }
//+------------------------------------------------------------------+
//| The function places an order or opens a position                 |
//| and plays the sound of success or error                          |
//+------------------------------------------------------------------+
void OrderSendWithAudio(void)
 {
  bool   res=true;
  MqlTick tick= {};
 
  ResetLastError();
  if(!SymbolInfoTick(Symbol(),tick))
    {
    Print("SymbolInfoTick() failed. Error code: ",GetLastError());
    PlaySound(InpFileNameErr);
    return;
    }
//--- send a request to the server
  switch(InpOrderType)
    {
    case ORDER_TYPE_BUY :
        res=ExtTrade.Buy(InpLots);
        break;
    case ORDER_TYPE_BUY_LIMIT :
        res=ExtTrade.BuyLimit(InpLots,NormalizeDouble(tick.ask-100*Point(),Digits()));
        break;
    case ORDER_TYPE_BUY_STOP :
        res=ExtTrade.BuyStop(InpLots,NormalizeDouble(tick.ask+100*Point(),Digits()));
        break;
    case ORDER_TYPE_SELL :
        res=ExtTrade.Sell(InpLots);
        break;
    case ORDER_TYPE_SELL_LIMIT :
        res=ExtTrade.SellLimit(InpLots,NormalizeDouble(tick.bid+100*Point(),Digits()));
        break;
    case ORDER_TYPE_SELL_STOP :
        res=ExtTrade.SellStop(InpLots,NormalizeDouble(tick.bid-100*Point(),Digits()));
        break;
    default :
        res=false;
    }
  if(!res)
    Print("Error ",GetLastError());
  Print(ExtTrade.ResultRetcodeDescription());
 
//--- if the request is accepted, play the ok.wav sound
  if(ExtTrade.ResultRetcode()==TRADE_RETCODE_DONE)
    PlaySound(InpFileNameOK);
  else
    PlaySound(InpFileNameErr);
 }

参照

リソース