how to make the continuous sound once some thing happen?

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
335
vx0532 2014.01.20 02:53 #
 
gchrmt4:


[Some simplifications in the following; it is not 100% literally true]

There are two ways of representing a string in the computer's memory. A) Ansi. One byte per character, therefore limited to 255 different characters and unable to represent characters from writing systems such as Kanji or Arabic. W) Unicode. Two bytes per character, and therefore able to represent a much larger range of characters. (The W stands for "wide".)

All Windows API functions which accept string parameters come in two versions, A and W, e.g. PlaySoundA and PlaySoundW, or ShellExecuteA and ShellExecuteW, or CreateFileA and CreateFileW. If your code uses Ansi strings then you use the A version. If your code uses Unicode strings, then you use the W version.

Apart from the different parameter types, the A and W functions are identical. Therefore, the Microsoft documentation contains a single entry for PlaySound(), not separate entries for PlaySoundA() and PlaySoundW().

When writing code in a language such as C, header files and compiler settings will automatically translate the use of e.g. PlaySound() to either PlaySoundA() or PlaySoundW() as appropriate. In other words, you would normally write code using references to PlaySound() rather than PlaySoundA() or PlaySoundW(), and the compiler would quietly convert this to either PlaySoundA() or PlaySoundW().

In languages such as MQL4, there is no such automatic conversion and mapping of functions names. You have to use declare and use the underlying functions exported by the Windows API. Therefore, MQL4 code must explicitly import and use PlaySoundA() or PlaySoundW(), rather than referring to PlaySound(). This is also convenient because there would otherwise be a conflict between MQL4’s built-in PlaySound() function and an attempt to import the Windows function. (The same applies to the Win32 MessageBox function versus the built-in MQL4 MessageBox.)

The additional trick in the above code is that you cancel a repeating sound by passing a null pointer to PlaySound() instead of a string. MQL4 has no (easy) way of doing this with a single function import. However, the existence of separate A and W functions means that it is possible to import the same function twice in MQL4, with different parameter lists, so that PlaySoundW() can be used as a way of passing a null string parameter.

Finally: when compiling with build 574 of MT4, MQL4 code uses Unicode strings rather than Ansi strings. Therefore, all references (including the imports) in the above code to PlaySoundA() would need to be changed to PlaySoundW(), and vice versa.

Thank you for all your time and patience, it is very clear.

avatar
1
anotherbrian 2014.04.15 15:35 #
 

With the recent move to build 600, I'm now just learning some higher level programming and the unicode and additional data types are not totally clear to me yet. I'm looking for some help here. I'm trying to play an mp3 file.

When I drag this script to the chart I hear the default system sound. I've tried all kinds of different things, here is the latest. Also, I'm not sure if the issue is with my code or with Windows 7, I have had issues playijg sound files before using mt4 built-in PlaySound() function, had to allow the file to be played by opening the files properties.

#import "winmm.dll"

int PlaySoundA(short &a[],int,int);

int PlaySoundW(short &a[],int,int);

#import


When I want to play the file, I call mp3()

void mp3()

{

string mp3file=StringConcatenate(TerminalInfoString(TERMINAL_DATA_PATH),"\\MQL4\\Files\\Sounds\\test.mp3");

short ump3file[];

StringToShortArray(mp3file,ump3file);

PlaySoundA(ump3file,0,0);

PlaySoundW(0,0,0);

MessageBox("This is very annoying...");

}

avatar
315
sunshineh 2015.03.03 23:22 #
 

Hi,

has anybody a working solution to Play a local sound file with PlaySoundA from "winmm.dll"?

I tried all this code snippets and can only hear a metatrader Default sound :-(

Back to topics list   | 1 2  

To add comments, please log in or register