How to create a sound from a VC++ .NET program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?=

    How to create a sound from a VC++ .NET program

    I want to create a sound to alert the user when some event occurs.
    How do I do it from my VC++ .NET window form program?
  • David Lowndes

    #2
    Re: How to create a sound from a VC++ .NET program

    >I want to create a sound to alert the user when some event occurs.
    >How do I do it from my VC++ .NET window form program?
    MessageBeep would probably be the easiest API to use. If you need a
    more complex facility, have a look at the PlaySound API. For the .Net
    world, it looks like similar facilities are available from the
    System.Media namespace - SystemSound::Pl ay for instance.

    Dave

    Comment

    • =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?=

      #3
      Re: How to create a sound from a VC++ .NET program

      Dear Dave:

      I use the following code to call MessageBeep from my VC++ .net window form
      program

      [DllImport("user 32.dll", SetLastError=tr ue)]
      static bool MessageBeep(UIN T type);

      MessageBeep(-1);

      However I do not hear a beep sound.

      Also I do not see the System::Media namespace in my Visual Studio 2003 .NET.

      Kueishiong Tu

      "David Lowndes" wrote:
      I want to create a sound to alert the user when some event occurs.
      How do I do it from my VC++ .NET window form program?
      >
      MessageBeep would probably be the easiest API to use. If you need a
      more complex facility, have a look at the PlaySound API. For the .Net
      world, it looks like similar facilities are available from the
      System.Media namespace - SystemSound::Pl ay for instance.
      >
      Dave
      >

      Comment

      • David Lowndes

        #4
        Re: How to create a sound from a VC++ .NET program

        >I use the following code to call MessageBeep from my VC++ .net window form
        >program
        >
        >[DllImport("user 32.dll", SetLastError=tr ue)]
        >static bool MessageBeep(UIN T type);
        You don't need to go to that rigmarole - this is C++ not C# :)

        Just #include<window s.hand add the call to the API.
        >MessageBeep(-1);
        Try MessageBeep(MB_ OK) - it should produce whatever system sound you
        have set up in the Control Panel Sound setting.
        >Also I do not see the System::Media namespace in my Visual Studio 2003 .NET.
        I don't have VS2003 installed, but the following works for me with
        VS2008:

        #include "stdafx.h"
        #include<window s.h>

        #pragma comment( lib, "User32.lib " )

        using namespace System;

        int main(array<Syst em::String ^^args)
        {
        Console::WriteL ine(L"Hello World");
        MessageBeep( -1 );

        System::Media:: SystemSounds::B eep->Play();
        return 0;
        }

        Dave

        Comment

        • =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?=

          #5
          Re: How to create a sound from a VC++ .NET program

          Dear Dave:

          "David Lowndes" wrote:
          I use the following code to call MessageBeep from my VC++ .net window form
          program

          [DllImport("user 32.dll", SetLastError=tr ue)]
          static bool MessageBeep(UIN T type);
          >
          You don't need to go to that rigmarole - this is C++ not C# :)
          >
          Just #include<window s.hand add the call to the API.
          >
          If I don't do the DllImport, the IDE will complain unresolved token
          "MessageBee p" when I try to build the solution in VS2003 VC++ .NET.
          I don't have VS2003 installed, but the following works for me with
          VS2008:
          >
          #include "stdafx.h"
          #include<window s.h>
          >
          #pragma comment( lib, "User32.lib " )
          >
          using namespace System;
          >
          int main(array<Syst em::String ^^args)
          {
          Console::WriteL ine(L"Hello World");
          MessageBeep( -1 );
          >
          System::Media:: SystemSounds::B eep->Play();
          return 0;
          }
          >
          I try the same code on my VS2008 VC++ express, but I still get no sound even
          I turn the speaker to the loudest level and my window media player does play
          sound.

          Kueishiong Tu

          Comment

          • David Lowndes

            #6
            Re: How to create a sound from a VC++ .NET program

            >I don't have VS2003 installed, but the following works for me with
            >VS2008:
            >>
            >#include "stdafx.h"
            >#include<windo ws.h>
            >>
            >#pragma comment( lib, "User32.lib " )
            >>
            >using namespace System;
            >>
            >int main(array<Syst em::String ^^args)
            >{
            > Console::WriteL ine(L"Hello World");
            > MessageBeep( -1 );
            >>
            > System::Media:: SystemSounds::B eep->Play();
            > return 0;
            >}
            >>
            >
            >I try the same code on my VS2008 VC++ express, but I still get no sound even
            >I turn the speaker to the loudest level and my window media player does play
            >sound.
            If you use the Control Panel, Sound applet and play the default beep
            from there, does that work?

            Dave

            Comment

            • =?Utf-8?B?S3VlaXNoaW9uZyBUdQ==?=

              #7
              Re: How to create a sound from a VC++ .NET program

              If you use the Control Panel, Sound applet and play the default beep
              from there, does that work?
              >
              Dave
              >
              It does not initially. I fix it. Now it works fine. Thank you very much for
              your help.

              Kueishiong Tu

              Comment

              Working...