Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.Win32;
- namespace HowTo
- {
- class WebClickSound
- {
- /// <summary>
- /// Enables or disables the web browser navigating click sound.
- /// </summary>
- public static bool Enabled
- {
- get
- {
- RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEventsSchemesAppsExplorerNavigating.Current");
- string keyValue = (string)key.GetValue(null);
- return String.IsNullOrEmpty(keyValue) == false && keyValue != """";
- }
- set
- {
- string keyValue;
- if (value)
- {
- keyValue = "%SystemRoot%\Media\";
- if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor > 0)
- {
- // XP
- keyValue += "Windows XP Start.wav";
- }
- else if (Environment.OSVersion.Version.Major == 6)
- {
- // Vista
- keyValue += "Windows Navigation Start.wav";
- }
- else
- {
- // Don't know the file name so I won't be able to re-enable it
- return;
- }
- }
- else
- {
- keyValue = """";
- }
- // Open and set the key that points to the file
- RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEventsSchemesAppsExplorerNavigating.Current", true);
- key.SetValue(null, keyValue, RegistryValueKind.ExpandString);
- isEnabled = value;
- }
- }
- }
- }
- private void Form1_Activated(object sender, EventArgs e)
- {
- // Disable the sound when the program has focus
- WebClickSound.Enabled = false;
- }
- private void Form1_Deactivate(object sender, EventArgs e)
- {
- // Enable the sound when the program is out of focus
- WebClickSound.Enabled = true;
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- // Enable the sound on app exit
- WebClickSound.Enabled = true;
- }
- webBrowser1.DocumentText = "<h1>Hello, world!</h1>";
- webBrowser1.Document.OpenNew(true);
- webBrowser1.Document.Write("<h1>Hello, world!</h1>");
- 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);
- }
- // backup value
- RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEventsSchemesAppsExplorerNavigating.Current");
- string BACKUP_keyValue = (string)key.GetValue(null);
- // write nothing
- key = Registry.CurrentUser.OpenSubKey(@"AppEventsSchemesAppsExplorerNavigating.Current", true);
- key.SetValue(null, "", RegistryValueKind.ExpandString);
- // do navigation ...
- // write backup key
- RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEventsSchemesAppsExplorerNavigating.Current", true);
- key.SetValue(null, BACKUP_keyValue, RegistryValueKind.ExpandString);
Add Comment
Please, Sign In to add comment