当前位置:  开发笔记 > 编程语言 > 正文

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

如何解决《如何在WebBrowser控件中禁用单击声音》经验,为你挑选了2个好方法。

我使用Javascript单击webbrowser控件中的链接.但我不想听到IE的"咔嗒"声.

有没有办法做到这一点?

PS

我不想更改系统设置.

我已经看过这个(如何在你的应用程序中禁用WebBrowser'点击声音'),但Document.Write对我来说不是一个选项.

James Crowle.. 44

对于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 = newsign1.0)



1> James Crowle..:

对于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 = newsign1.0)



2> Dennis..:

我已将此功能包装到即用型课程中.我使用了所选答案和MSDN参考的部分信息.

希望这对某人有用.

用法

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

URLSecurityZoneAPI

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

    /// 
    /// Specifies where to set the feature control value
    /// http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx
    /// 
    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
    }

    /// 
    /// InternetFeaturelist
    /// http://msdn.microsoft.com/en-us/library/ms537169%28v=VS.85%29.aspx
    /// 
    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
    }

    /// 
    /// Enables or disables a specified feature control. 
    /// http://msdn.microsoft.com/en-us/library/ms537168%28VS.85%29.aspx
    ///             
    [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);

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

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

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

  }


很奇怪,但我必须将最后一个参数设置为true:URLSecurityZoneAPI.InternetSetFeatureEnabled(URLSecurityZoneAPI.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS,URLSecurityZoneAPI.SetFeatureOn.PROCESS,true);
推荐阅读
黄晓敏3023
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有