PlaySound
Hàm này phát một tệp âm thanh.
cpp
bool PlaySound(
string filename // tên tệp
);
1
2
3
2
3
Tham số
filename
[truyền vào] Đường dẫn đến một tệp âm thanh. Nếu filename
=NULL, việc phát sẽ dừng lại.
Giá trị trả về
true
– nếu tệp được tìm thấy, ngược lại – false
.
Ghi chú
Tệp phải được đặt trong thư mục terminal_directory\Sounds hoặc thư mục con của nó. Chỉ các tệp WAV được phát.
Gọi hàm PlaySound()
với tham số NULL sẽ dừng việc phát.
Hàm PlaySound()
không hoạt động trong Strategy Tester.
Ví dụ:
cpp
#include <Trade\Trade.mqh>
#define MAGIC (123)
//--- tham số đầu vào
input string InpFileNameOK = "ok.wav"; // tệp âm thanh thành công
input string InpFileNameErr = "timeout.wav"; // tệp âm thanh lỗi
input ENUM_ORDER_TYPE InpOrderType = ORDER_TYPE_BUY_LIMIT; // loại lệnh
input double InpLots = 0.1; // khối lượng
//--- biến toàn cục
CTrade ExtTrade;
//+------------------------------------------------------------------+
//| Hàm khởi động chương trình script |
//+------------------------------------------------------------------+
void OnStart()
{
//--- thiết lập số ma thuật và loại lệnh theo cài đặt của ký hiệu
ExtTrade.SetExpertMagicNumber(MAGIC);
ExtTrade.SetTypeFillingBySymbol(Symbol());
//--- gọi hàm đặt lệnh hoặc mở vị thế với phát âm thanh
OrderSendWithAudio();
}
//+------------------------------------------------------------------+
//| Hàm đặt lệnh hoặc mở vị thế |
//| và phát âm thanh thành công hoặc lỗi |
//+------------------------------------------------------------------+
void OrderSendWithAudio(void)
{
bool res=true;
MqlTick tick= {};
ResetLastError();
if(!SymbolInfoTick(Symbol(),tick))
{
Print("SymbolInfoTick() thất bại. Mã lỗi: ",GetLastError());
PlaySound(InpFileNameErr);
return;
}
//--- gửi yêu cầu đến máy chủ
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("Lỗi ",GetLastError());
Print(ExtTrade.ResultRetcodeDescription());
//--- nếu yêu cầu được chấp nhận, phát âm thanh ok.wav
if(ExtTrade.ResultRetcode()==TRADE_RETCODE_DONE)
PlaySound(InpFileNameOK);
else
PlaySound(InpFileNameErr);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Xem thêm