How to disable click sound in WebBrowser Control

前端 未结 7 1339
庸人自扰
庸人自扰 2020-11-29 02:11

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

Is there any way to do this?

P.S.

7条回答
  •  日久生厌
    2020-11-29 02:27

    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.

    Hope this is useful to someone.

    Usage

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

提交回复
热议问题