DotNet-Flemmotron/NibblePoker.Win32Wrappers/Beeps.cs
Herwin Bozet 86e5dcd318 Initial commit
Update .gitignore, ConsoleApp1.csproj, and 23 more files...
2025-01-19 23:08:37 +01:00

46 lines
1.3 KiB
C#

using System.ComponentModel;
using System.Runtime.InteropServices;
using NibblePoker.Win32Bindings;
namespace NibblePoker.Win32Wrappers;
// ReSharper disable MemberCanBePrivate.Global
public static class Beeps {
public enum SoundTypes : uint {
Fallback = User32.MB_FALLBACK,
CriticalStop = User32.MB_ICONERROR,
Asterisk = User32.MB_ICONINFORMATION,
Question = User32.MB_ICONQUESTION, // Doesn't work on W11 !!
Exclamation = User32.MB_ICONWARNING,
Default = User32.MB_OK,
}
public static void Beep(uint frequency, uint durationMs) {
if(!Kernel32.Beep(frequency, durationMs)) {
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
public static void Beep(uint type) {
if(!User32.MessageBeep(type)) {
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
public static void Beep(SoundTypes type) {
Beep((uint)type);
}
public static bool BeepSafe(uint frequency, uint durationMs) {
return Kernel32.Beep(frequency, durationMs);
}
public static bool BeepSafe(uint type) {
return User32.MessageBeep(type);
}
public static bool BeepSafe(SoundTypes type) {
return BeepSafe((uint)type);
}
}