Mega Code Archive

 
Categories / Delphi / Multimedia
 

How to Play a Sound When the Mouse Enters a (Delphi) Component

Title: How to Play a Sound When the Mouse Enters a (Delphi) Component All descendants of TComponent send a CM_MOUSEENTER and CM_MOUSELEAVE messages when the mouse enters and leaves the bounds of the component. You will need to write a message handler for the respective messages if you wish to respond to them - and play a sound, for example, when the mouse "enters" the component. ~~~~~~~~~~~~~~~~~~~~~~~~~ uses MMSystem, ... TMyComponent = class(TComponent) private procedure CMMouseEnter(var msg: TMessage) ; message CM_MOUSEENTER; procedure CMMouseLeave(var msg: TMessage) ; message CM_MOUSELEAVE; end; implementation procedure TMyComponent.CMMouseEnter(var msg: TMessage) ; begin sndPlaySound('c:\mysound.wav', snd_Async or snd_NoDefault) end; procedure TMyComponent.CMMouseLeave(var msg: TMessage) ; begin sndPlaySound(nil, snd_Async or snd_NoDefault) ; end; ~~~~~~~~~~~~~~~~~~~~~~~~~