PlaySound函数的代码
时间: 2024-04-17 20:26:03 浏览: 145
Sure, here is an example code snippet for the PlaySound function in C++:
```cpp
#include <Windows.h>
#include <mmsystem.h>
int main() {
PlaySound(TEXT("sound.wav"), NULL, SND_FILENAME | SND_ASYNC);
return 0;
}
```
In this code, we include the necessary header files `Windows.h` and `mmsystem.h` to use the PlaySound function. We then call the PlaySound function with the name of the sound file ("sound.wav" in this example) as the first parameter. The second parameter is for specifying a sound device, but we pass NULL to use the default device. The third parameter is a combination of flags, where `SND_FILENAME` indicates that we are passing a file name, and `SND_ASYNC` plays the sound asynchronously.
Please note that you need to have the necessary sound file ("sound.wav" in this example) in the same directory as your program or provide the correct path to the file.
阅读全文