Jump to content
david_navigator

Enumerating Windows Sounds

Recommended Posts

Is there a better way to get the list of Windows sounds as displayed in this Sounds dropdown without simply enumerating the contents of the %windir%\Media folder ?

 

image.png.f8e4e7d645a90b3dd284d9a47356a5a5.png

Share this post


Link to post
3 hours ago, david_navigator said:

Is there a better way to get the list of Windows sounds as displayed in this Sounds dropdown without simply enumerating the contents of the %windir%\Media folder ?

What's wrong with enumerating that folder? That is likely what the dialog is doing.  Why do you expect there to be an API that provides that list?  Not everything in a system UI has a dedicated API behind it.

Share this post


Link to post

There might be a better way.

You can enumerate over registry.

HKEY_CURRENT_USER\AppEvents\Schemes

Then you know wich sound belong to wich action.

 

If I missunderstood question, I am sorry.

Share this post


Link to post
1 hour ago, Remy Lebeau said:

What's wrong with enumerating that folder? That is likely what the dialog is doing.  Why do you expect there to be an API that provides that list?  Not everything in a system UI has a dedicated API behind it.

Nothing. I just didn't want to do that IF there was an API that was the prefered method, especially as I couldn't find any documentation as to whether the folder name is localized in none English Windows.

Edited by david_navigator

Share this post


Link to post
Guest
5 hours ago, david_navigator said:

I just didn't want to do that IF there was an API that was the prefered method,

for well, with just only line and a "ListBox" you can take all "wav" files used by MSWindows!

  • MSWindows 10 64bits
  • RAD Studio 10.3.3 Arch
  • VCL or FMX Project
uses
  System.IOUtils;

procedure TForm1.btn_MSWindowsMediaFilesClick(Sender: TObject);
begin
  { TFilterPredicate = reference to function(const Path: string;const SearchRec: TSearchRec): Boolean; }
  { TSearchOption.soTopDirectoryOnly or TSearchOption.soAllDirectories }
  //
  ListBox1.Items.Clear;
  //
  ListBox1.Items.AddStrings(                                                                                 { }
    TDirectory.GetFiles('C:\Windows\Media', '*.wav', TSearchOption.soAllDirectories { , TFilterPredicate } ) { }
    );
end;

 

image.thumb.png.b085b1804db2e2f89904c09df2933a2b.png

 

or scroll through the "Computador\HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default" key in your Registry and select what you want to find, for example!or 

 

 

hug

Share this post


Link to post
procedure GetRegistrySounds;
var
  phkResult: HKEY;
  dwIndex: DWORD;
  HResult: Longint;
  lpName: LPWSTR;
  SubKeyNames: TStringList;
  i: Integer;
  Len: Longint;
  Buf: array[0..1023] of Char;
  dwResult: DWORD;
  ResultString: string;
begin
  SubKeyNames := TStringList.Create;
  try
    dwIndex := 0;
    lpName := StrAlloc(1024);
    HResult := RegOpenKeyEx(HKEY_CURRENT_USER, PChar('AppEvents\Schemes\Apps\.Default'), 0, KEY_READ, phkResult);
    if (HResult = ERROR_SUCCESS) then
      begin
        while (HResult = ERROR_SUCCESS) do
          begin
            HResult := RegEnumKey(phkResult, dwIndex, lpName, 1024);
            if (HResult = ERROR_SUCCESS) then
              begin
                SubKeyNames.Add(lpName);
                Inc(dwIndex);
              end;
           end;
        RegCloseKey(phkResult);
      end;
    StrDispose(lpName);
    for i := 0 to (SubKeyNames.Count - 1) do
      begin
        if (RegOpenKeyEx(HKEY_CURRENT_USER, PChar('AppEvents\Schemes\Apps\.Default\' + SubKeyNames[i] + '\.Current'), 0, KEY_READ, phkResult) = ERROR_SUCCESS) then
          begin
            Len := 1024 * SizeOf(Char);
            case RegQueryValueEx(phkResult, PChar(''), nil, nil, PByte(@Buf[0]), @Len) of
              ERROR_SUCCESS:
                SetString(ResultString, Buf, Len div SizeOf(Char) - 1);
              ERROR_MORE_DATA:
                begin
                  SetLength(ResultString, Len div SizeOf(Char) - 1);
                  if (RegQueryValueEx(phkResult, PChar(''), nil, nil, PByte(ResultString), @Len) = ERROR_SUCCESS) then
                    SetLength(ResultString, Len div SizeOf(Char) - 1)
                else
                  ResultString := '';
                end;
            end;
            RegCloseKey(phkResult);
            if (ResultString <> '') then
              begin
                dwResult := ExpandEnvironmentStrings(PChar(ResultString), buf, 1024);
                if (dwResult <> 0) then
                  ResultString := string(buf);
                // here we have a result to work with
                Form1.Memo1.Lines.Add(ResultString);
              end;
          end;
      end;
  finally
    SubKeyNames.Free;
  end;
end;
Edited by KodeZwerg

Share this post


Link to post

Above code will readout registry data.

Modify Form1.Memo1 to your needs.

 

//edit

Code aint perfect designed, just a working release.

 

Have fun 🙂

Edited by KodeZwerg

Share this post


Link to post
Guest
37 minutes ago, KodeZwerg said:

Above code will readout registry data.

better dont trust the Registry as "right"! --> somebody can dont have it as your...you see?

  • an user, can dont have previlegies on Registry key, for example, if a user is very restrict for use just some part of your system at all
    • on MSWin we can have more than an user, and each user can have some restriction on system!
  • better check the "real files on disk" - using a folder default or specific for this task, can be the "key"
    • for example, an user can dont have access to "user folder of other user", etc..
  • if the files exist, then, just fill the list (TStringList, TList, and sub-classes) - of course, if the files is "corrupted"... nothing to do with it!

 

hug

Edited by Guest

Share this post


Link to post
Guest
3 hours ago, KodeZwerg said:

My bad. Your best.

Peace 

no. no. no. your app, your code!

what be better for you! :classic_wink:

 

hug

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×