我想禁用Web浏览器声音,但我认为这是不可能的,因此我看到可以在高于win xp的系统上禁用应用程序声音,现在我只需要知道该怎么做,而我找不到它!
当前代码:
Form.ActiveForm.Hide();
webBrowser1.ScriptErrorsSuppressed = true;
try
{
webBrowser1.Navigate(args[2], null, null, "User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Xbox; Xbox One)");
}
catch (Exception ex)
{
Environment.Exit(0);
}
我不认为有webrowser.noSound的东西,我也用activeform.hide()来隐藏webbrowser
最佳答案
首先添加此 namespace :
using System.Runtime.InteropServices;
现在,您只需禁用所有音频输出即可。试试这些代码:
[DllImport("winmm.dll")]
public static extern int GetVolume(IntPtr p, out uint volume);
[DllImport("winmm.dll")]
public static extern int SetVolume(IntPtr p, uint volume);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Save the current volume
int save;
GetVolume(IntPtr.Zero, out save);
this.FormClosing += delegate
{
// Restore the volume
SetVolume(IntPtr.Zero, save);
};
// Now you can mute sounds
SetVolume(IntPtr.Zero, 0);
string url = "http://www.example.com";
this.webBrowser1.Navigate(url);
}
更新:
您可以Read This其他人也回答了这个问题。
更新2:
You can put it inside a static class and either make the CoInternetSetFeatureEnabled method public, or add an additional bridge method that calls it after converting the parameters from a more usable form, if necessary.
阅读这两个类似的问题并禁用声音:
Question1 Question2
更新3:
对于IE7及更高版本,您可以使用CoInternetSetFeatureEnabled:
// Constants
private const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;
private const int SET_FEATURE_ON_THREAD = 0x00000001;
private const int SET_FEATURE_ON_PROCESS = 0x00000002;
private const int SET_FEATURE_IN_REGISTRY = 0x00000004;
private const int SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008;
private const int SET_FEATURE_ON_THREAD_INTRANET = 0x00000010;
private const int SET_FEATURE_ON_THREAD_TRUSTED = 0x00000020;
private const int SET_FEATURE_ON_THREAD_INTERNET = 0x00000040;
private const int SET_FEATURE_ON_THREAD_RESTRICTED = 0x00000080;
// Necessary dll import
[DllImport("urlmon.dll")]
[PreserveSig]
[return:MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(
int FeatureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);
......
// You can call the CoInternetSetFeatureEnabled like this:
CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true);
这是Source
更新4:
How to mute windows sound
关于c# - C#禁用Webbrowser声音/应用程序声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28217411/