Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

acoustic signals - adding own events

Posted on 1998-08-21
2
Medium Priority
?
208 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

597 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