How to simulate a MessageBeep() function ?

  • Thread starter Thread starter AndreB
  • Start date Start date
A

AndreB

Hi,

I'm triing to find a way to simulate a MessageBeep() function (from C++) in
C# ?

Any help would be appreciated, TIA, AndreB.
 
I think you will have to use the windows API. Don't know any direct way of
doing it in Managed code.
 
I wrote a little class to do the Beepin'

//-----------------------------------------------------------------
//-----------------------------------------------------------------
/// <summary>
/// Used for the different beep types
/// </summary>
public enum SoundType : int {
/// <summary>
/// A default beep. If no sound card is available, this will use the
speaker
/// </summary>
SIMPLEBEEP = -0x0001,
/// <summary>
/// The OK Beep
/// </summary>
MB_OK = 0x0000,
/// <summary>
/// The Icon Hand Beep
/// </summary>
MB_ICONHAND = 0x0010,
/// <summary>
/// The Question Beep
/// </summary>
MB_ICONQUESTION = 0x0020,
/// <summary>
/// The exclamation beep
/// </summary>
MB_ICONEXCLAMATION = 0x0030,
/// <summary>
/// the asterisk beep
/// </summary>
MB_ICONASTERISK = 0x0040
}

/// <summary>
/// Used to do the VB Beep function
/// </summary>
public class Beep {
private Beep(){}
/// <summary>
/// Just like the VB Beep function. Use the API.SoundType enum for
beep types
/// </summary>
[DllImport("User32")]
public static extern bool MessageBeep(SoundType SoundType);
}
//-----------------------------------------------------------------
//-----------------------------------------------------------------
 
Add a reference to 'Microsoft.VisualBasic',

Call 'Microsoft.VisualBasic.Interaction.Beep()'.


Seth Wenzel said:
I wrote a little class to do the Beepin'

//-----------------------------------------------------------------
//-----------------------------------------------------------------
/// <summary>
/// Used for the different beep types
/// </summary>
public enum SoundType : int {
/// <summary>
/// A default beep. If no sound card is available, this will use the
speaker
/// </summary>
SIMPLEBEEP = -0x0001,
/// <summary>
/// The OK Beep
/// </summary>
MB_OK = 0x0000,
/// <summary>
/// The Icon Hand Beep
/// </summary>
MB_ICONHAND = 0x0010,
/// <summary>
/// The Question Beep
/// </summary>
MB_ICONQUESTION = 0x0020,
/// <summary>
/// The exclamation beep
/// </summary>
MB_ICONEXCLAMATION = 0x0030,
/// <summary>
/// the asterisk beep
/// </summary>
MB_ICONASTERISK = 0x0040
}

/// <summary>
/// Used to do the VB Beep function
/// </summary>
public class Beep {
private Beep(){}
/// <summary>
/// Just like the VB Beep function. Use the API.SoundType enum for
beep types
/// </summary>
[DllImport("User32")]
public static extern bool MessageBeep(SoundType SoundType);
}
//-----------------------------------------------------------------
//-----------------------------------------------------------------

Saurabh said:
I think you will have to use the windows API. Don't know any direct way of
doing it in Managed code.

C++)
in
 
* "AndreB said:
I'm triing to find a way to simulate a MessageBeep() function (from C++) in
C# ?

There is no 1:1 replacement. I would continue using 'MessageBeep'
through p/invoke.
 
Back
Top