7

I have a WPF application that uses the navigation window and frames to navigate between xaml pages. Every time it goes between the pages it makes a click sound. Is there a way to disable that?

So far I have tried this:

namespace FrameTesting
{
public partial class MainWindow : NavigationWindow
{
    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;

    public MainWindow()
    {
        int feature = FEATURE_DISABLE_NAVIGATION_SOUNDS;
        CoInternetSetFeatureEnabled(feature, SET_FEATURE_ON_PROCESS, true);
        InitializeComponent();
    }

    [DllImport("urlmon.dll")]
    [PreserveSig]
    [return: MarshalAs(UnmanagedType.Error)]
    static extern int CoInternetSetFeatureEnabled(
         int FeatureEntry,
         [MarshalAs(UnmanagedType.U4)] int dwFlags,
         bool fEnable);
}

}

Robert
  • 6,086
  • 19
  • 59
  • 84
  • Did you work this one out, Robert? I can't make it work on Win7 x64 with IE10 either. – Matt Hamilton Sep 17 '13 at 00:55
  • I never got this working. I ended up abandoning the idea of using the navigation window and went with just setting a content area with a datatemplate when navigating between pages. – Robert Sep 17 '13 at 22:11

2 Answers2

2

The function you want is called CoInternetSetFeatureEnabled and you can find some additional information in the accepted answer to this question.

Since WPF uses the WebBrowser control under the hood, this should work for the Frame control as well.

Community
  • 1
  • 1
Josh
  • 68,005
  • 14
  • 144
  • 156
  • I have updated my question with some code. Did I do something wrong because I still hear the clicking? – Robert Jun 07 '10 at 05:12
  • Is it IE7 or higher? That should work but maybe you need to do it after the WebBrowser control has loaded. It may need to initialize something else in urlmon first. The only other thing I can suggest is I've seen the DllImport specify ExactSpelling=true but I can't imagine why that would apply here. – Josh Jun 07 '10 at 05:26
  • I'm running IE8. Setting the ExactSpelling=true doesn't work. How would I know when the WebBrowser control has loaded to add this code? – Robert Jun 12 '10 at 17:41
1

Put this on your main class:

private const int Feature = 21; //FEATURE_DISABLE_NAVIGATION_SOUNDS
private const int SetFeatureOnProcess = 0x00000002;

[DllImport("urlmon.dll")]
[PreserveSig]
[return: MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(int featureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);

And then add this on your code (Window Loaded):

CoInternetSetFeatureEnabled(Feature, SetFeatureOnProcess, true);
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474