HowTo Disable WebBrowser 'Click Sound' in your app only

前端 未结 5 528
南旧
南旧 2020-12-05 17:52

The \'click sound\' in question is actually a system wide preference, so I only want it to be disabled when my application has focus and then re-enable when the application

相关标签:
5条回答
  • 2020-12-05 18:15

    You disable it by changing Internet Explorer registry value of navigating sound to "NULL":

    Registry.SetValue("HKEY_CURRENT_USER\\AppEvents\\Schemes\\Apps\\Explorer\\Navigating\\.Current","","NULL");
    

    And enable it by changing Internet Explorer registry value of navigating sound to "C:\Windows\Media\Cityscape\Windows Navigation Start.wav":

    Registry.SetValue("HKEY_CURRENT_USER\\AppEvents\\Schemes\\Apps\\Explorer\\Navigating\\.Current","","C:\Windows\Media\Cityscape\Windows Navigation Start.wav");
    
    0 讨论(0)
  • 2020-12-05 18:22

    If you want to use replacing Windows Registry, use this:

    // backup value
    RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current");
    string BACKUP_keyValue = (string)key.GetValue(null);
    
    // write nothing
    key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current", true);
    key.SetValue(null, "",  RegistryValueKind.ExpandString);
    
    // do navigation ...
    
    // write backup key
    RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current", true);
    key.SetValue(null, BACKUP_keyValue,  RegistryValueKind.ExpandString);
    
    0 讨论(0)
  • 2020-12-05 18:26

    I've noticed that if you use WebBrowser.Document.Write rather than WebBrowser.DocumentText then the click sound doesn't happen.

    So instead of this:

    webBrowser1.DocumentText = "<h1>Hello, world!</h1>";
    

    try this:

    webBrowser1.Document.OpenNew(true);
    webBrowser1.Document.Write("<h1>Hello, world!</h1>");
    
    0 讨论(0)
  • 2020-12-05 18:27

    Definitely feels like a hack, but having done some research on this a long time ago and not finding any other solutions, probably your best bet.

    Better yet would be designing your application so it doesn't require many annoying page reloads.. for example, if you're refreshing an iframe to check for updates on the server, use XMLHttpRequest instead. (Can you tell that I was dealing with this problem back in the days before the term "AJAX" was coined?)

    0 讨论(0)
  • 2020-12-05 18:40
    const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;
    const int SET_FEATURE_ON_PROCESS = 0x00000002;
    
    [DllImport("urlmon.dll")]
    [PreserveSig]
    [return: MarshalAs(UnmanagedType.Error)]
    static extern int CoInternetSetFeatureEnabled(int FeatureEntry,
                                                  [MarshalAs(UnmanagedType.U4)] int dwFlags,
                                                  bool fEnable);
    
    static void DisableClickSounds()
    {
        CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS,
                                    SET_FEATURE_ON_PROCESS,
                                    true);
    }
    
    0 讨论(0)
提交回复
热议问题