Solved

acoustic signals - adding own events

Posted on 1998-08-21
2
206 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 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

Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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