Subscribe
Follow @shai_rai
Today I’m working on a editor application for JavaScript and HTML5 using WPF WebBrowser, when working with the browser control I noticed that each time I reload the page or click some links there is an annoying sound.
Because my application is reloading the page very frequently I had to disable the WebBrowser sound.
In order to do that I used CoInternetSetFeatureEnabled (Enables or disables a specified feature control.), I’ve made a simple test application to demonstrate this feature.
Download Demo Project
Make sure your application has reference to - using System.Runtime.InteropServices;
And add the below code in your class:
private const int Feature = 21; //FEATURE_DISABLE_NAVIGATION_SOUNDSprivate const int SetFeatureOnProcess = 0x00000002; [DllImport("urlmon.dll")][PreserveSig][return: MarshalAs(UnmanagedType.Error)]static extern int CoInternetSetFeatureEnabled(int featureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable);
Using the On \ Off button you can Enable or Disable the WebBrowser sound.
private void BtnOnOffClick(object sender, RoutedEventArgs e){ if (btnOnOff.Content.Equals("Sound On")) { btnOnOff.Content = "Sound Off"; CoInternetSetFeatureEnabled(Feature, SetFeatureOnProcess, true); } else { btnOnOff.Content = "Sound On"; CoInternetSetFeatureEnabled(Feature, SetFeatureOnProcess, false); }}
Enjoy
No Comments