tags:

views:

747

answers:

4

I'm using a TWebbrowser component in my Delphi app, whose content I load programmatically:

(aWebBrowser.Document as IPersistStreamInit).
                               Load(TStreamAdapter.Create(aMemoryStream))

On every Load the component produces an annoying click sound. Can this be disabled?
TIA

+1  A: 

Any chance that this is the Windows standard "Start Navigation" sound (see "Control Panel" - "Sounds and Audio Devices")?

Tomalak
+6  A: 

This is a windows setting. I'm not sure your application should change that setting.

Davy Landman
+2  A: 

OK, here's what I tried:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnActivate := AppActivate;
  Application.OnDeactivate := AppDeactivate;
end;

procedure TForm1.AppActivate(Sender: TObject);
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    OpenKey('AppEvents\Schemes\Apps\Explorer\Navigating\.Current', False);
    if ReadString('') <> '' then
      RememberSoundFile := ReadString('');
    WriteString('', '');
  finally
    Free;
  end;
end;

procedure TForm1.AppDeactivate(Sender: TObject);
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    OpenKey('AppEvents\Schemes\Apps\Explorer\Navigating\.Current', False);
    WriteString('', RememberSoundFile);
  finally
    Free;
  end;
end;

It's fugly but it works. :-) While I basically agree with Davy this solution at least has the advantage that other applications won't be affected.
I may add it as a user option to disable the click, but personally I really want it gone!

stevenvh
"other applications won't be affected" well, while your application is running all the other applications will be affected. Not to mention the fact that if your application crashes or your settings isn't restored at all.. (to make it a little more robust do this in a try catch block in your app.dpr)
Davy Landman
This is setting the underlying storage that IE uses to control the setting. It affects all applications. While your app has focus, other apps won't make sound. Use the documented CoInternetSetFeatureEnabled to set it for just your app. No need to toggle it as your app gains and loses focus.
Rob Kennedy
I did accept Nick's answer. As for the other apps, for me it's even better if they keep quiet while they don't have the focus. Davy, you're right about the crash situation, but my applications never crash (yeah, right :-))
stevenvh
+14  A: 

Take a look at the CoInternetSetFeatureEnabled procedure in URLMON.DLL, as documented here. Enabling FEATURE_DISABLE_NAVIGATION_SOUNDS for your app will do what you need.

Nick Bradbury