Solved

acoustic signals - adding own events

Posted on 1998-08-21
2
195 Views
Last Modified: 2012-05-07
in the control panel for acoustic signals there are several entries defining which sound to play on which event. this does not only include windows-intern events but also those of installed software.

in the registry-key HKEY_CURRENT_USER\AppEvents... the schemes and labels can be found.

now my question: what do i have to do
a) to programmatically manipulate the "properties of the acoustic signals" (i.e. in the control panel for acoustic signals my own events shall be defined among the others)?
b) in my application to fire an event which causes a predefined sound to be played ?

i know this question is not *easy* but i ain't got no more points at the moment. you know how this comes, i guess...

i'm willing to ask a dummy question for the one who answers this one complete when i've got more points to give the one an adequate amount of points.

any answer solving this problem will be accepted:
url, source fragments, common explanation etc.

i need the answer relatively quick. please - help.

regards,

Black Death.
0
Comment
Question by:BlackDeath
2 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 50 total points
ID: 1337396
Hi,
I just whipped this together. Maybe it's what you're looking for?:

unit AudioEvents;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Registry, MMSystem;

type
  TAudioEvents = class(TRegistry)
  private
    FDefAppName: string;
    function GetKeys( const sBaseKey: string; List: TStrings ): Boolean;
    function AppName( const sAppName: string ): string;
    { Private declarations }
  protected
    { Protected declarations }
  public
    constructor Create;
    function CreateEvent( const sAppName, sEventName, sEventLabel, sAudioFilename: string ): Boolean;
    function SetEventFilename( const sAppName, sEventName, sAudioFilename: string ): Boolean;
    function GetEventFilename( const sAppName, sEventName: string ): string;
    function SetEventLabel( const sEventName, sEventLabel: string ): Boolean;
    function GetEventLabel( const sEventName: string ): string;
    function SetDefaultAppName( const sAppName: string ): Boolean;
    function GetApps( AppList: TStrings ): Boolean;
    function GetAppEvents( const sAppName: string; EventList: TStrings; const bScan: Boolean ): Boolean;
    function PlayEvent( const sAppName, sEventName: string ): Boolean;
    { Public declarations }
  published
    { Published declarations }
  end;

implementation

const
  keyAppEvents   = '\AppEvents';
  keyEventLabels = keyAppEvents   + '\EventLabels';
  keySchemes     = keyAppEvents + '\Schemes';
  keyApps        = keySchemes     + '\Apps';


//==============================================================================

constructor TAudioEvents.Create;
begin
  inherited Create;
  RootKey := HKEY_CURRENT_USER;
end;

//==============================================================================

function TAudioEvents.GetKeys( const sBaseKey: string; List: TStrings ): Boolean;
begin
  if Assigned( List ) then
  begin
    if ( OpenKey( sBaseKey, False ) ) then
    begin
      GetKeyNames( List );
      Result := True;
    end else
    begin
      List.Clear;
      Result := False;
    end;
  end else Result := False;
end;

//------------------------------------------------------------------------------

function TAudioEvents.AppName( const sAppName: string ): string;
begin
  if ( sAppName = '' )
  then begin
    if ( FDefAppName = '' )
    then Result := '.Default'
    else REsult := FDefAppName;
  end else Result := sAppName;
end;

//==============================================================================

function TAudioEvents.CreateEvent( const sAppName, sEventName, sEventLabel, sAudioFilename: string ): Boolean;
begin
  if ( OpenKey( keyApps + '\' + AppName( sAppName ) + '\' + sEventName + '\.current', True ) )
  then begin
    WriteString( '', sAudioFilename );
    if ( OpenKey( keyEventLabels + '\' + sEventName + '\.current', True ) )
    then begin
      WriteString( '', sEventLabel );
      Result := True;
    end else Result := False;
  end else Result := False;
end;

//------------------------------------------------------------------------------

function TAudioEvents.SetEventFilename( const sAppName, sEventName, sAudioFilename: string ): Boolean;
begin
  if ( OpenKey( keyApps + '\' + AppName( sAppName ) + '\' + sEventName + '\.current', False ) )
  then begin
    WriteString( '', sAudioFilename );
    Result := True;
  end else Result := False;
end;

//------------------------------------------------------------------------------

function TAudioEvents.GetEventFilename( const sAppName, sEventName: string ): string;
begin
  if ( OpenKey( keyApps + '\' + AppName( sAppName ) + '\' + sEventName + '\.current', False ) )
  then Result := ReadString( '' )
  else Result := '';
end;

//------------------------------------------------------------------------------

function TAudioEvents.SetEventLabel( const sEventName, sEventLabel: string ): Boolean;
begin
  if ( OpenKey( keyEventLabels + '\' + sEventName + '\.current', True ) )
  then begin
    WriteString( '', sEventLabel );
    Result := True;
  end else Result := False;
end;

//------------------------------------------------------------------------------

function TAudioEvents.GetEventLabel( const sEventName: string ): string;
begin
  if ( OpenKey( keyEventLabels + '\' + sEventName + '\.current', False ) )
  then Result := ReadString( '' )
  else Result := '';
end;

//------------------------------------------------------------------------------

function TAudioEvents.SetDefaultAppName( const sAppName: string ): Boolean;
begin
  FDefAppName := sAppName;
  Result := ( FDefAppName <> '' );
end;

//------------------------------------------------------------------------------

function TAudioEvents.GetApps( AppList: TStrings ): Boolean;
begin
  Result := GetKeys( keyApps, AppList );
end;

//------------------------------------------------------------------------------

function TAudioEvents.GetAppEvents( const sAppName: string; EventList: TStrings; const bScan: Boolean ): Boolean;
var
  iIndex: Integer;
begin
  if ( GetKeys( keyApps + '\' + AppName( sAppName ), EventList ) ) then
  begin
    if ( bScan ) then
    begin
      for iIndex := EventList.Count - 1 downto 0
      do if ( GetEventFilename( AppName( sAppName ), EventList[ iIndex ] ) = '' )
      then EventList.Delete( iIndex );
      Result := ( EventList.Count > 0 );
    end else Result := True;
  end else Result := False;
end;

//------------------------------------------------------------------------------

function TAudioEvents.PlayEvent( const sAppName, sEventName: string ): Boolean;
begin
  Result := sndPlaySound( PChar( GetEventFilename( sAppName, sEventName ) ), SND_ASYNC );
end;

end.

Usage:

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TAudioEvents.Create do begin
    PlayEvent( '', ListBox1.Items[ ListBox1.ItemIndex ] );
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TAudioEvents.Create do begin
    GetAppEvents( '', ListBox1.Items, False );
  end;
end;


 AudioEvent.PlayEvent( 'Explorer', 'EmptyRecycleBin' );

/// John
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1337397
hi, john!

thanx for your answer. i wasn't able to read it on friday, because our domain server went to sleep. this weekend i browsed through the help files of visual c++ developer studio and guess what i've found:

PlaySound and sndPlaySound.

so i thought this must be possible with delphi, too. i scanned the win32.hlp, delphi.hlp and several other help files, but could not find it. what i did not scan was mm.hlp.

and - there it is. your answer helped me in the way that i do now know, *where* this function is declared.

furthermore, i don't have to break my mind on thinking about how to put it into code. this one's a nice unit.

thanxalot,

Black Death.
so,
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now