《Sound output by C script in WinCC.doc》由会员分享,可在线阅读,更多相关《Sound output by C script in WinCC.doc(2页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Sound output by C script in WinCCTop of FormThis entry is available in the following languages: Bottom of FormEntry ID:748844Date:06/11/2002QUESTION:How can I output a sound via C script in WinCC? ANSWER:Attached is a small example. This C action is behind a button, so that you just click to the but
2、ton to produce a sound. C action: #include apdefap.hvoid OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)#pragma code (Winmm.dll )VOID WINAPI PlaySoundA ( char* pszSound, char* hmode, DWORD dwflag );#pragma code()PlaySoundA(C:Winnt.400Mediatada.
3、wav,NULL,1);Requirement for this function is a sound card.Explanation of the PlaySoundA function: 1. Parameter char* pszSound:Here you specify the complete path to where your sound file (*.wav file) is located. 2. Parameter char* hmode:Here you always specify 0. 3. Parameter DWORD dwflag.SND_SYNC =
4、0x0000: sound file is played once and the script waits until it has been played to the endSND_ASYNC = 0x0001: sound file is played once, the script is processed in parallelSND_NODEFAULT = 0x0002: if the sound file is not found, then no default value is played, but nothing at all.SND_LOOP = 0x0008: r
5、epeats the sound file until the next PlaySoundA call comes (only possible with 0x0001) = always specify 0x0009.These parameters can also be combined but bit-by-bit Ors (e.g.: SND_ASYNC | SND_LOOP) Note:If you want to use the beep of the computers internal loudspeaker instead of a sound file, then im
6、plement the following script:Since the internal loudspeaker is addressed, there is no need for a sound card. #include apdefap.h void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)#pragma code (Kernel32.dll)BOOL Beep( DWORD dwFreq, DWORD dwDuration); /dwFreq defines the frequency of the beep in hertz /dwDuration specifies the duration of the beep in milliseconds#pragma code()Beep(1000,100); /Example: frequency 1000 hertz, 100 milliseconds Give us your feedback.Questions / suggestions re this Entry ID