My application uses the Webbrowser control to access internal sites. I want to mute the ding sound that occurs when a dialog is displayed on an internal site.
It would be best if I could mute the sound of my application. If you mute the entire system, you should restore the original settings (mute state and volume) after processing. Also, I believe this problem can be solved with WinAPI and don't want to use any library. My company uses Windows 10.
I tried this noseratio's answer but it didn't get muted.
Webbrowser disable all audio output - from online radio to youtube
I checked other past questions, but they didn't mention how to restore the system sound, or they needed to use a third-party library, so I couldn't solve the problem.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WinformsWB
{
public partial class Form1 : Form
{
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr h, out uint dwVolume);
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr h, uint dwVolume);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// save the current volume
uint _savedVolume;
waveOutGetVolume(IntPtr.Zero, out _savedVolume);
this.FormClosing += delegate
{
// restore the volume upon exit
waveOutSetVolume(IntPtr.Zero, _savedVolume);
};
// mute
waveOutSetVolume(IntPtr.Zero, 0);
this.webBrowser1.Navigate("http://youtube.com");
}
}
}