?
Solved

acoustic signals - adding own events

Posted on 1998-08-21
2
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 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