Play a sound on mouse enter

Posted in Components

Use CM_MOUSEENTER and CM_MOUSELEAVE messages like this:

uses MMSystem;

   TYourObject = class(TAnyControl)
  ...
  private
    procedure CMMouseEnter(var AMsg: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var AMsg: TMessage); message CM_MOUSELEAVE;
  ...
  end;

implementation

procedure TYourObject.CMMouseEnter(var AMsg: TMessage);
begin
  sndPlaySound('c:\win98\media\ding.wav',snd_Async or snd_NoDefault);
end;

procedure TYourObject.CMMouseLeave(var AMsg: TMessage);
begin
  sndPlaySound(nil,snd_Async or snd_NoDefault);
end;