【问题标题】:How to disable click sound in WebBrowser Control如何在 WebBrowser 控件中禁用单击声音
【发布时间】:2008-12-25 20:36:03
【问题描述】:

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

有什么办法吗?

附:

【问题讨论】:

    标签: .net winforms audio webbrowser-control


    【解决方案1】:

    对于IE7及以上,你可以这样使用:

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

    使用以下 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);
    

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

    【讨论】:

    • 在带有 IE8 的 Vista 64 上非常适合我。
    • 也适用于我,Win7 64bit IE9(注意:该应用是 32 位的)
    • 有效。 Vista 64 位 IE10。此外,如果指向 MS 反馈站点的链接不起作用,请尝试删除 &wa=wsignin1.0 或单击此处 connect.microsoft.com/VisualStudio/feedback/…
    【解决方案2】:

    我已将此功能包装到一个即用型类中。我使用了所选答案和MSDN reference中的部分信息。

    希望这对某人有用。

    用法

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

    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);
        }
    
      }
    

    【讨论】:

    • 完美,非常感谢。注意:如果您希望它静音,使用中的最后一个参数需要为 false。 URLSecurityZoneAPI.InternetSetFeatureEnabled(URLSecurityZoneAPI.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS, URLSecurityZoneAPI.SetFeatureOn.PROCESS, false);
    • 非常感谢,工作正常。需要在申请启动时申请一次。
    • 很奇怪,但我必须将最后一个参数设置为 true: URLSecurityZoneAPI.InternetSetFeatureEnabled(URLSecurityZoneAPI.InternetFeaturel‌ist.DISABLE_NAVIGATION_SOUNDS, URLSecurityZoneAPI.SetFeatureOn.PROCESS, true);
    • 如果属性是“禁用导航声音”,那么布尔值应该是 true 禁用,false 启用。不过,鉴于 Microsoft 的最佳实践指南,该属性是否定的,这令人惊讶。
    【解决方案3】:

    正如 cmets 所指出的,以及 @James Crowley 的回答,确实有可能。


    如果您在 IE 中导航,并因此在该控件中导航,您将获得点击。除非您更改设置,或者像那个链接那样伪造它,否则不,您无法摆脱点击。

    【讨论】:

    • 不正确 - 请参阅下面 James Crowley 的回答。
    【解决方案4】:

    我不能让它在 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)
    

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

    <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
    

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

    【讨论】:

    • 嘿,你是怎么把最后一部分放到vb.net的??如果我复制/粘贴 ,我会收到一堆错误
    【解决方案5】:

    导入 System.Runtime.InteropServices

    qxxx 使用这些导入

    【讨论】:

      【解决方案6】:

      您唯一的其他选择是将计算机静音,但这不是一个好主意...

      【讨论】:

      • 一个相当幽默的回答。
      【解决方案7】:

      所以这是已知的限制......

      是否有任何肮脏的黑客/解决方法,例如挂钩 ActiveX 的声音调用并禁用它们(不确定是否可能不深入)

      【讨论】:

      • 这不是一个已知的限制......它是系统为用户提供的功能。因此,用户可以控制它。这就像说 html 页面无法更改 IE 标题栏的颜色是一个已知限制。
      • 罗伯特这是一个“控件”而不是应用程序,所以这是一个限制。如果 Windows 不提供访问某些注册表项的方法,那么这些注册表项不会成为限制。
      猜你喜欢
      • 2010-09-21
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      相关资源
      最近更新 更多