Microsoft Knowledge Base Email Alertz

Visual C++ will play different sounds at the end of a build, depending on the success of the build. Without a sound system installed, Visual C++ calls MessageBeep().

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 122158 - Last Review: November 18, 2003 - Revision: 2.0

Configuring Sound in Visual C++ Development Environment

This article was previously published under Q122158

On This Page

SUMMARY

Visual C++ will play different sounds at the end of a build, depending on the success of the build. Without a sound system installed, Visual C++ calls MessageBeep().

If there is a sound system installed in the computer, Visual C++ calls sndPlaySound(), using the Multimedia API, with specific sound names. If the sound names listed below are not in the system's registry, Visual C++ does not make any sound at all.


   Build State            sndPlaySound()      MessageBeep()
                          Sound Name          Beep Type
   -----------------------------------------------------------
   Build is up to date    BuildUpToDate       MB_ICONASTERISK
   Build has errors       BuildError          MB_ICONEXCLAMATION
   Build has warnings     BuildWarning        MB_ICONQUESTION
   Build complete         BuildComplete       MB_ICONASTERISK
   Build cancelled        <nothing>           <nothing>
				
In addition, Visual C++ version 4.0 supports the following sound states:
   State                  sndPlaySound()      MessageBeep()
                          Sound Name          Beep Type
   -----------------------------------------------------------
   Breakpoint Hit         MSVC_HitBP         <nothing>
   Error in Output        MSVC_OutputError   <nothing>
   Warning in Output      MSVC_OutputWarning <nothing>
				
If a sound card is not installed, you can modify the system sounds by choosing the Sound icon from the Control Panel. If you have a sound card installed, you need to modify the registry to add the sndPlaySound() sound names to enable sound before you change the sounds in the Control Panel.

MORE INFORMATION

Under Windows NT registry, the sounds need to be placed in:
   HKEY_CURRENT_USER\Control Panel\Sounds
				
You can use the following sample C program to automatically add these sounds, or you can use REGEDT32.EXE to directly modify the registry. After the modifications, your registry should contain the following lines for Visual C++ 2.x:
   BuildComplete:REG_SZ:tada.wav,Build Complete
   BuildUpToDate:REG_SZ:ding.wav,Build Up To Date
   BuildError:REG_SZ:ding.wav,Build Error
   BuildWarning:REG_SZ:ding.wav,Build Warning
				
After the modifications, your registry should contain the following lines for Visual C++ 4.0:
   BuildComplete : REG_SZ : tada.wav,MSDev: Build Complete
   BuildUpToDate : REG_SZ : ding.wav,MSDev: Build Up To Date
   BuildError : REG_SZ : ding.wav,MSDev: Build Error
   BuildWarning : REG_SZ : ding.wav,MSDev: Build Warning
				

Sample Code

/* Compile options needed: Default build options for a console
                  application.
*/ 

#include <windows.h>
#include <stdio.h>
#include <string.h>

char *sound[4] = { "BuildComplete", "BuildUpToDate",
                   "BuildError", "BuildWarning" };
#if _MSC_VER == 1000  // using Visual C++ 4.0
char *soundValue[4] = { "tada.wav,MSDev: Build Complete",
                        "ding.wav,MSDev: Build Up To Date",
                        "ding.wav,MSDev: Build Error",
                        "ding.wav,MSDev: Build Warning" };
#else  // using Visual C++ 2.x
char *soundValue[4] = { "tada.wav,Build Complete",
                        "ding.wav,Build Up To Date",
                        "ding.wav,Build Error",
                        "ding.wav,Build Warning" };
#endif

void main( void )
{
int i;
HKEY hCPanel;
HKEY hSounds;

if ((ERROR_SUCCESS != RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel",
                       0, KEY_SET_VALUE, &hCPanel)) ||
                (ERROR_SUCCESS != RegOpenKeyEx(hCPanel, "Sounds",
                 0, KEY_SET_VALUE, &hSounds)))
   {
    printf("Error opening HKEY_CURRENT_USER\\Control Panel\\Sounds\n");
    exit(-1);
   }

for (i=0; i<4; i++)
       if (ERROR_SUCCESS != RegSetValueEx(hSounds, sound[i], 0, REG_SZ,
        (unsigned char*) soundValue[i], strlen(soundValue[i]) + 1))
       printf("Could not set sound: %s\n", sound[i]);

RegCloseKey(hSounds);
RegCloseKey(hCPanel);

printf("Sounds were successfully added\n");
exit(0);
}

APPLIES TO
  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 4.0 Standard Edition
Keywords: 
kbcode kbinfo KB122158
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate