locked
[SOLVED]Sound on button click RRS feed

  • Question

  • hi does anyone know how to get the Asterisk sound to play when clicking a button in VC++ ?
    ive created the Event handler but not sure of what code to use. thanks
    Tuesday, August 8, 2006 10:49 AM

Answers

  • Hi,

    if you're using .NET 2.0, try with the following:

    System.Media.SystemSounds.Asterisk.Play();

    Andrej

    Tuesday, August 8, 2006 10:53 AM

All replies

  • Hi,

    if you're using .NET 2.0, try with the following:

    System.Media.SystemSounds.Asterisk.Play();

    Andrej

    Tuesday, August 8, 2006 10:53 AM
  • i get errors when compiling, are there any files i need to #include ?
    Tuesday, August 8, 2006 10:57 AM
  • SoundPlayer (and SystemSounds) class is included in system.dll so you have to reference that... What kind of error are you getting?

    Andrej

    Tuesday, August 8, 2006 11:00 AM
  • ------ Build started: Project: test, Configuration: Debug Win32 ------
    Compiling...
    PowerPeer.cpp
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2882: 'System' : illegal use of namespace identifier in expression
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.Media' must have class/struct/union
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.SystemSounds' must have class/struct/union
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.Asterisk' must have class/struct/union
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.Play' must have class/struct/union
    Form1.cpp
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2882: 'System' : illegal use of namespace identifier in expression
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.Media' must have class/struct/union
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.SystemSounds' must have class/struct/union
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.Asterisk' must have class/struct/union
    c:\documents and settings\dion1\my documents\visual studio 2005\projects\test\test\Form1.h(2882) : error C2228: left of '.Play' must have class/struct/union
    Generating Code...
    Build log was saved at "file://c:\Documents and Settings\Dion1\My Documents\Visual Studio 2005\Projects\test\test\Debug\BuildLog.htm"
    test - 10 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    long list
    Tuesday, August 8, 2006 11:04 AM
  • In your codes includes:

        (IE:
              using namespace System;
              using namespace System::IO;
              // ,,,
              )

       Add a reference to the System::Media namespace.
    Tuesday, August 8, 2006 11:12 AM
  • ah its ok i managed to get it to work by using the following code:

                 System::Media::SystemSounds::Asterisk->Play();

    just needed to replace the . with :: and all works fine now
    i didnt need to add any extra namespace's, i just added that line and it worked. thanks for your help
    Tuesday, August 8, 2006 11:15 AM
  • A good programming habit to make is to learn how to tell between different languages. Otherwise you may find code to use in the wrong language and be baffled as to why it doesn't compile.

    A rule of thumb you can use:

    C++ use :: and ->
    C# and VB use .
    Tuesday, August 8, 2006 12:15 PM