我的网络浏览器:
XAML:
//...
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
//...
<my:WindowsFormsHost Name="windowsFormsHost"/>
Run Code Online (Sandbox Code Playgroud)
C#背后的代码:
System.Windows.Forms.WebBrowser Browser = new System.Windows.Forms.WebBrowser();
windowsFormsHost.Child = Browser;
Run Code Online (Sandbox Code Playgroud)
我的问题是如何禁用所有音频输出.
我找到了这个:
C#:
private const int Feature = 21; //FEATURE_DISABLE_NAVIGATION_SOUNDS
private 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);
Run Code Online (Sandbox Code Playgroud)
它很好,但是这段代码只能禁用"咔嗒"声,所以在这种情况下它的那种无用.
我只想从我的应用程序100%静音,没有声音.
我已经读过,在这个webbrowser中,它需要通过Windows Sounds来完成,但我真的不知道我在代码中无法做到这一点.
nos*_*tio 11
这是你如何轻松地做到这一点.但不是特定于WebBrowser,而是按照您的要求执行:我只想从我的应用程序100%静音,根本没有声音.
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");
}
}
}
Run Code Online (Sandbox Code Playgroud)