如何在WebBrowser控件中禁用单击声音

时间:2021-07-09 20:44:41

I use Javascript to click a link in the webbrowser control. But I don't want to hear IE's "click" sound.

我使用Javascript在webbrowser控件中单击一个链接。但我不想听到IE的“咔哒”声。

Is there any way to do this?

有什么办法吗?

P.S.

注:

  • I don't want to change system settings.
  • 我不想改变系统设置。
  • I've seen this one (HowTo Disable WebBrowser 'Click Sound' in your app only) but Document.Write is not an option for me.
  • 我看过这个(如何在你的应用中禁用WebBrowser 'Click Sound')但是文档。写作不是我的选择。

7 个解决方案

#1


44  

For IE7 and above, you can use this:

对于IE7及以上版本,你可以使用以下工具:

int feature = FEATURE_DISABLE_NAVIGATION_SOUNDS;
CoInternetSetFeatureEnabled(feature, SET_FEATURE_ON_PROCESS, true);

using the following DLL imports

使用以下DLL导入

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;

...

[DllImport("urlmon.dll")]
[PreserveSig]
[return:MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(
int FeatureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);

(found on the MS feedback site as a solution from the WPF team: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=345528&wa=wsignin1.0)

(在MS反馈网站上找到一个来自WPF团队的解决方案:https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=345528&wa=wsignin1.0)

#2


12  

I have wrapped this functionality into a ready-to-use class. I used part of the information from the selected answer and the MSDN reference.

我已经将这个功能封装到一个现成的类中。我使用了部分来自所选答案和MSDN引用的信息。

Hope this is useful to someone.

希望这对某人有用。

Usage

使用

URLSecurityZoneAPI.InternetSetFeatureEnabled(URLSecurityZoneAPI.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS, URLSecurityZoneAPI.SetFeatureOn.PROCESS, false);

URLSecurityZoneAPI

URLSecurityZoneAPI

  /// <summary>
  /// Enables or disables a specified Internet Explorer feature control
  /// Minimum availability: Internet Explorer 6.0
  /// Minimum operating systems: Windows XP SP2
  /// </summary>
  internal class URLSecurityZoneAPI
  {

    /// <summary>
    /// Specifies where to set the feature control value
    /// http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx
    /// </summary>
    public enum SetFeatureOn : int
    {
      THREAD = 0x00000001,
      PROCESS = 0x00000002,
      REGISTRY = 0x00000004,
      THREAD_LOCALMACHINE = 0x00000008,
      THREAD_INTRANET = 0x00000010,
      THREAD_TRUSTED = 0x00000020,
      THREAD_INTERNET = 0x00000040,
      THREAD_RESTRICTED = 0x00000080
    }

    /// <summary>
    /// InternetFeaturelist
    /// http://msdn.microsoft.com/en-us/library/ms537169%28v=VS.85%29.aspx
    /// </summary>
    public enum InternetFeaturelist : int
    {
      OBJECT_CACHING = 0,
      ZONE_ELEVATION = 1,
      MIME_HANDLING = 2,
      MIME_SNIFFING = 3,
      WINDOW_RESTRICTIONS = 4,
      WEBOC_POPUPMANAGEMENT = 5,
      BEHAVIORS = 6,
      DISABLE_MK_PROTOCOL = 7,
      LOCALMACHINE_LOCKDOWN = 8,
      SECURITYBAND = 9,
      RESTRICT_ACTIVEXINSTALL = 10,
      VALIDATE_NAVIGATE_URL = 11,
      RESTRICT_FILEDOWNLOAD = 12,
      ADDON_MANAGEMENT = 13,
      PROTOCOL_LOCKDOWN = 14,
      HTTP_USERNAME_PASSWORD_DISABLE = 15,
      SAFE_BINDTOOBJECT = 16,
      UNC_SAVEDFILECHECK = 17,
      GET_URL_DOM_FILEPATH_UNENCODED = 18,
      TABBED_BROWSING = 19,
      SSLUX = 20,
      DISABLE_NAVIGATION_SOUNDS = 21,
      DISABLE_LEGACY_COMPRESSION = 22,
      FORCE_ADDR_AND_STATUS = 23,
      XMLHTTP = 24,
      DISABLE_TELNET_PROTOCOL = 25,
      FEEDS = 26,
      BLOCK_INPUT_PROMPTS = 27,
      MAX = 28
    }

    /// <summary>
    /// Enables or disables a specified feature control. 
    /// http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx
    /// </summary>            
    [DllImport("urlmon.dll", ExactSpelling = true), PreserveSig, SecurityCritical, SuppressUnmanagedCodeSecurity]
    [return: MarshalAs(UnmanagedType.Error)]
    static extern int CoInternetSetFeatureEnabled(int featureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable);

    /// <summary>
    /// Determines whether the specified feature control is enabled. 
    /// http://msdn.microsoft.com/en-us/library/ms537164%28v=VS.85%29.aspx
    /// </summary>
    [DllImport("urlmon.dll", ExactSpelling = true), PreserveSig, SecurityCritical, SuppressUnmanagedCodeSecurity]
    [return: MarshalAs(UnmanagedType.Error)]
    static extern int CoInternetIsFeatureEnabled(int featureEntry, int dwFlags);

    /// <summary>
    /// Set the internet feature enabled/disabled
    /// </summary>
    /// <param name="feature">The feature from <c>InternetFeaturelist</c></param>
    /// <param name="target">The target from <c>SetFeatureOn</c></param>
    /// <param name="enabled">enabled the feature?</param>
    /// <returns><c>true</c> if [is internet set feature enabled] [the specified feature]; otherwise, <c>false</c>.</returns>
    public static bool InternetSetFeatureEnabled(InternetFeaturelist feature, SetFeatureOn target, bool enabled)
    {
      return (CoInternetSetFeatureEnabled((int)feature, (int)target, enabled) == 0);
    }

    /// <summary>
    /// Determines whether the internet feature is enabled.
    /// </summary>
    /// <param name="feature">The feature from <c>InternetFeaturelist</c></param>
    /// <param name="target">The target from <c>SetFeatureOn</c></param>
    /// <returns><c>true</c> if the internet feature is enabled; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsInternetSetFeatureEnabled(InternetFeaturelist feature, SetFeatureOn target)
    {
      return (CoInternetIsFeatureEnabled((int)feature, (int)target) == 0);
    }

  }

#3


2  

As noted by the comments, and the answer by @James Crowley, it is indeed possible.

正如评论和@James Crowley的回答所指出的,这确实是可能的。


If you navigate in IE, and thus that control, you'll get the click. Unless you change the settings, or fake it like that link, then no, you can't get rid of the click.

如果你在IE中导航,就会得到点击。除非你改变设置,或者像那个链接一样假装它,否则你无法摆脱点击。

#4


1  

I cant make it work on VB.net, tried this:

我不能让它在VB.net上工作,

Private Const FEATURE_DISABLE_NAVIGATION_SOUNDS As Integer = 21
Private Const SET_FEATURE_ON_THREAD As Integer = &H1
Private Const SET_FEATURE_ON_PROCESS As Integer = &H2
Private Const SET_FEATURE_IN_REGISTRY As Integer = &H4
Private Const SET_FEATURE_ON_THREAD_LOCALMACHINE As Integer = &H8
Private Const SET_FEATURE_ON_THREAD_INTRANET As Integer = &H10
Private Const SET_FEATURE_ON_THREAD_TRUSTED As Integer = &H20
Private Const SET_FEATURE_ON_THREAD_INTERNET As Integer = &H40
Private Const SET_FEATURE_ON_THREAD_RESTRICTED As Integer = &H80

Declare Function CoInternetSetFeatureEnabled Lib "urlmon.dll" ( _
ByVal FeatureEntry As Integer, ByVal dwFlags As Long, _
ByVal fEnable As Long) As Long

...

CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, True)

Edit: Found the problem, its within declaring. True one is:

编辑:发现问题,在声明中。真正的一个是:

<SecurityCritical, SuppressUnmanagedCodeSecurity, DllImport("urlmon.dll", ExactSpelling:=True)> _
Public Shared Function CoInternetSetFeatureEnabled(ByVal featureEntry As Integer, ByVal dwFlags As Integer, ByVal fEnable As Boolean) As Integer
End Function

Thanks to dmex at http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx

感谢dmex在http://msdn.microsoft.com/en-us/library/ms537168%的28vs.85%29aspx。

#5


1  

Imports System.Runtime.InteropServices < Imports System.Security

System.Runtime进口。InteropServices <进口system.security< p>

qxxx use those imports

qxxx使用这些进口

#6


0  

Your only other option is to mute the computer, but that's hardly a good idea...

你唯一的选择就是关掉电脑,但这并不是一个好主意。

#7


-1  

So this is known limitation then...

所以这就是我们所知道的限制。

Is there any dirty hack / workaround such as hooking sound calls of the ActiveX and disabling them (Not sure if it's possible without going too deep)

有没有什么不干净的方法,比如连接ActiveX的声音并禁用它们(不确定是否有可能,但不要太深入)

#1


44  

For IE7 and above, you can use this:

对于IE7及以上版本,你可以使用以下工具:

int feature = FEATURE_DISABLE_NAVIGATION_SOUNDS;
CoInternetSetFeatureEnabled(feature, SET_FEATURE_ON_PROCESS, true);

using the following DLL imports

使用以下DLL导入

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;

...

[DllImport("urlmon.dll")]
[PreserveSig]
[return:MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(
int FeatureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);

(found on the MS feedback site as a solution from the WPF team: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=345528&wa=wsignin1.0)

(在MS反馈网站上找到一个来自WPF团队的解决方案:https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=345528&wa=wsignin1.0)

#2


12  

I have wrapped this functionality into a ready-to-use class. I used part of the information from the selected answer and the MSDN reference.

我已经将这个功能封装到一个现成的类中。我使用了部分来自所选答案和MSDN引用的信息。

Hope this is useful to someone.

希望这对某人有用。

Usage

使用

URLSecurityZoneAPI.InternetSetFeatureEnabled(URLSecurityZoneAPI.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS, URLSecurityZoneAPI.SetFeatureOn.PROCESS, false);

URLSecurityZoneAPI

URLSecurityZoneAPI

  /// <summary>
  /// Enables or disables a specified Internet Explorer feature control
  /// Minimum availability: Internet Explorer 6.0
  /// Minimum operating systems: Windows XP SP2
  /// </summary>
  internal class URLSecurityZoneAPI
  {

    /// <summary>
    /// Specifies where to set the feature control value
    /// http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx
    /// </summary>
    public enum SetFeatureOn : int
    {
      THREAD = 0x00000001,
      PROCESS = 0x00000002,
      REGISTRY = 0x00000004,
      THREAD_LOCALMACHINE = 0x00000008,
      THREAD_INTRANET = 0x00000010,
      THREAD_TRUSTED = 0x00000020,
      THREAD_INTERNET = 0x00000040,
      THREAD_RESTRICTED = 0x00000080
    }

    /// <summary>
    /// InternetFeaturelist
    /// http://msdn.microsoft.com/en-us/library/ms537169%28v=VS.85%29.aspx
    /// </summary>
    public enum InternetFeaturelist : int
    {
      OBJECT_CACHING = 0,
      ZONE_ELEVATION = 1,
      MIME_HANDLING = 2,
      MIME_SNIFFING = 3,
      WINDOW_RESTRICTIONS = 4,
      WEBOC_POPUPMANAGEMENT = 5,
      BEHAVIORS = 6,
      DISABLE_MK_PROTOCOL = 7,
      LOCALMACHINE_LOCKDOWN = 8,
      SECURITYBAND = 9,
      RESTRICT_ACTIVEXINSTALL = 10,
      VALIDATE_NAVIGATE_URL = 11,
      RESTRICT_FILEDOWNLOAD = 12,
      ADDON_MANAGEMENT = 13,
      PROTOCOL_LOCKDOWN = 14,
      HTTP_USERNAME_PASSWORD_DISABLE = 15,
      SAFE_BINDTOOBJECT = 16,
      UNC_SAVEDFILECHECK = 17,
      GET_URL_DOM_FILEPATH_UNENCODED = 18,
      TABBED_BROWSING = 19,
      SSLUX = 20,
      DISABLE_NAVIGATION_SOUNDS = 21,
      DISABLE_LEGACY_COMPRESSION = 22,
      FORCE_ADDR_AND_STATUS = 23,
      XMLHTTP = 24,
      DISABLE_TELNET_PROTOCOL = 25,
      FEEDS = 26,
      BLOCK_INPUT_PROMPTS = 27,
      MAX = 28
    }

    /// <summary>
    /// Enables or disables a specified feature control. 
    /// http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx
    /// </summary>            
    [DllImport("urlmon.dll", ExactSpelling = true), PreserveSig, SecurityCritical, SuppressUnmanagedCodeSecurity]
    [return: MarshalAs(UnmanagedType.Error)]
    static extern int CoInternetSetFeatureEnabled(int featureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable);

    /// <summary>
    /// Determines whether the specified feature control is enabled. 
    /// http://msdn.microsoft.com/en-us/library/ms537164%28v=VS.85%29.aspx
    /// </summary>
    [DllImport("urlmon.dll", ExactSpelling = true), PreserveSig, SecurityCritical, SuppressUnmanagedCodeSecurity]
    [return: MarshalAs(UnmanagedType.Error)]
    static extern int CoInternetIsFeatureEnabled(int featureEntry, int dwFlags);

    /// <summary>
    /// Set the internet feature enabled/disabled
    /// </summary>
    /// <param name="feature">The feature from <c>InternetFeaturelist</c></param>
    /// <param name="target">The target from <c>SetFeatureOn</c></param>
    /// <param name="enabled">enabled the feature?</param>
    /// <returns><c>true</c> if [is internet set feature enabled] [the specified feature]; otherwise, <c>false</c>.</returns>
    public static bool InternetSetFeatureEnabled(InternetFeaturelist feature, SetFeatureOn target, bool enabled)
    {
      return (CoInternetSetFeatureEnabled((int)feature, (int)target, enabled) == 0);
    }

    /// <summary>
    /// Determines whether the internet feature is enabled.
    /// </summary>
    /// <param name="feature">The feature from <c>InternetFeaturelist</c></param>
    /// <param name="target">The target from <c>SetFeatureOn</c></param>
    /// <returns><c>true</c> if the internet feature is enabled; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsInternetSetFeatureEnabled(InternetFeaturelist feature, SetFeatureOn target)
    {
      return (CoInternetIsFeatureEnabled((int)feature, (int)target) == 0);
    }

  }

#3


2  

As noted by the comments, and the answer by @James Crowley, it is indeed possible.

正如评论和@James Crowley的回答所指出的,这确实是可能的。


If you navigate in IE, and thus that control, you'll get the click. Unless you change the settings, or fake it like that link, then no, you can't get rid of the click.

如果你在IE中导航,就会得到点击。除非你改变设置,或者像那个链接一样假装它,否则你无法摆脱点击。

#4


1  

I cant make it work on VB.net, tried this:

我不能让它在VB.net上工作,

Private Const FEATURE_DISABLE_NAVIGATION_SOUNDS As Integer = 21
Private Const SET_FEATURE_ON_THREAD As Integer = &H1
Private Const SET_FEATURE_ON_PROCESS As Integer = &H2
Private Const SET_FEATURE_IN_REGISTRY As Integer = &H4
Private Const SET_FEATURE_ON_THREAD_LOCALMACHINE As Integer = &H8
Private Const SET_FEATURE_ON_THREAD_INTRANET As Integer = &H10
Private Const SET_FEATURE_ON_THREAD_TRUSTED As Integer = &H20
Private Const SET_FEATURE_ON_THREAD_INTERNET As Integer = &H40
Private Const SET_FEATURE_ON_THREAD_RESTRICTED As Integer = &H80

Declare Function CoInternetSetFeatureEnabled Lib "urlmon.dll" ( _
ByVal FeatureEntry As Integer, ByVal dwFlags As Long, _
ByVal fEnable As Long) As Long

...

CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, True)

Edit: Found the problem, its within declaring. True one is:

编辑:发现问题,在声明中。真正的一个是:

<SecurityCritical, SuppressUnmanagedCodeSecurity, DllImport("urlmon.dll", ExactSpelling:=True)> _
Public Shared Function CoInternetSetFeatureEnabled(ByVal featureEntry As Integer, ByVal dwFlags As Integer, ByVal fEnable As Boolean) As Integer
End Function

Thanks to dmex at http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx

感谢dmex在http://msdn.microsoft.com/en-us/library/ms537168%的28vs.85%29aspx。

#5


1  

Imports System.Runtime.InteropServices < Imports System.Security

System.Runtime进口。InteropServices <进口system.security< p>

qxxx use those imports

qxxx使用这些进口

#6


0  

Your only other option is to mute the computer, but that's hardly a good idea...

你唯一的选择就是关掉电脑,但这并不是一个好主意。

#7


-1  

So this is known limitation then...

所以这就是我们所知道的限制。

Is there any dirty hack / workaround such as hooking sound calls of the ActiveX and disabling them (Not sure if it's possible without going too deep)

有没有什么不干净的方法,比如连接ActiveX的声音并禁用它们(不确定是否有可能,但不要太深入)