Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationWindow Click Sound

Tags:

c#

wpf

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

}

like image 921
Robert Avatar asked Jun 07 '10 04:06

Robert


2 Answers

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.

like image 158
Josh Avatar answered Oct 06 '22 20:10

Josh


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);
like image 41
Ionică Bizău Avatar answered Oct 06 '22 20:10

Ionică Bizău