Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use PlaySound function in C language

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "C language PlaySound function how to use", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "C language PlaySound function how to use" this article.

1 usage

PlaySound is the API function used to play sound in windows.

The function interfaces are as follows:

BOOL PlaySound (LPCSTR pszSound, HMODULE hmod,DWORD fdwSound)

2 parameters

PszSound is used to specify the file to be played, which can be the name of the resource or the path of the music file. If it is empty (NULL), the sound being played is stopped. PlaySound can only play WAV files.

Hmod is generally set to NULL unless you want to point to the resource identifier (that is, fdwSound is defined as SND_RESOURCE).

FdwSound is used to specify the playback mode. The parameters are as follows:

SND_APPLICATION

Play the sound with the association specified by the application.

SND_ALIAS

The pszSound parameter specifies an alias for system events in the registry or WIN.INI.

SND_ALIAS_ID

The pszSound parameter specifies a predefined sound identifier.

SND_ASYNC

The sound is played asynchronously, and the PlaySound function returns immediately after it starts playing.

SND_FILENAME

The pszSound parameter specifies the name of the WAVE file.

SND_LOOP

The sound must be played repeatedly and must be used with the SND_ASYNC flag.

SND_MEMORY

Play the sound loaded into memory, where pszSound is the pointer to the sound data.

SND_NODEFAULT

Do not play the default sound. Without this flag, PlaySound will play the default sound when no sound is found.

SND_NOSTOP

PlaySound does not interrupt the original sound broadcast and immediately returns to FALSE.

SND_NOWAIT

If the driver is busy, the function does not play the sound and returns immediately.

SND_PURGE

Stop all sounds related to the calling task. If the parameter pszSound is NULL, all sounds are stopped, otherwise, the sounds specified by pszSound are stopped.

SND_RESOURCE

The pszSound parameter is the identifier of the WAVE resource, so the hmod parameter is used.

SND_SYNC

The sound is played synchronously, and the PlaySound function returns after the playback.

SND_SYSTEM

If it is the background window, when this flag is set, the sound is assigned to the audio conferencing system notification sound. The system Volume Control Program (sndvol) displays the sound notified by the volume slider control system. Setting this flag will control the volume slider down. If this flag is not set, the sound is assigned to the default audio conference application process.

3 header file and static file # include# include#pragma comment (lib, "Winmm.lib") 4 music path

These are all the contents of the article "how to use PlaySound functions in C language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report