🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.multimedia
5 messages
5 total messages Started by Nicholas Gessler Fri, 10 Aug 2001 05:16
Changing a PlaySound path name on the fly...
#1235
Author: Nicholas Gessler
Date: Fri, 10 Aug 2001 05:16
19 lines
1651 bytes
Hi,

In the "Weird Program" application I had some questions about a while ago,
I've been trying to change the "media" directory path name on the fly to
accommodate both Win98 and WinNT, each having the "media" folder in a
different directory (windows, and winnt).  I have been trying different
combinations of the AnsiString( ) function but none of the ones I've tried
seem to please the compiler.  Can anyone give me a nudge in the right
direction?  The code looks like:

        if (X == 10) PlaySound("c:\\WINNT\\media\\jungle asterisk.wav", "",
SND_ASYNC);
        if (X == 20) PlaySound("c:\\WINNT\\media\\jungle close.wav", "",
SND_ASYNC);

And I want to be able to switch the string "WINNT" with "windows."

Cheers,
Nick
Re: Changing a PlaySound path name on the fly...
#1236
Author: Yoto Yotov
Date: Fri, 10 Aug 2001 05:23
9 lines
1004 bytes
> And I want to be able to switch the string "WINNT" with "windows."

Read the following FAQ: "Get the location of the Windows directory or 
the Windows system directory" at http://www.bcbdev.com/faqs/faq28.htm.

Good luck!

-- 
Yoto Yotov
Re: Changing a PlaySound path name on the fly...
#1239
Author: Nicholas Gessler
Date: Sat, 11 Aug 2001 17:07
9 lines
1425 bytes
Yoto Yotov <yoto@NOSPAMgmx.fr> wrote in message
news:MPG.15dd39c3e95d87759896ac@newsgroups.borland.com...
> Read the following FAQ: "Get the location of the Windows directory or the
Windows system directory" at http://www.bcbdev.com/faqs/faq28.htm.

Thanks, but now I get an "invalid pointer addition" message:
        if (X == 10) PlaySound(WinDir + "\\media\\jungle asterisk.wav", "",
SND_ASYNC);
Re: Changing a PlaySound path name on the fly...
#1240
Author: Yoto Yotov
Date: Sat, 11 Aug 2001 18:31
26 lines
1704 bytes
> Thanks, but now I get an "invalid pointer addition" message:
>         if (X == 10) PlaySound(WinDir + "\\media\\jungle asterisk.wav", "",
> SND_ASYNC);

Here's how your code may look like:

  String FileName(WinDir);
  FileName += "\\media\\jungle asterisk.wav";
  PlaySound(FileName.c_str(), NULL, SND_ASYNC | SND_FILENAME);

Note that your code assumes that this file exists.  However, on most 
systems (including mine), this file is not available.  A more correct 
approach is to use the user's default sounds such "SystemExclamation", 
"SystemQuestion", "SystemHand", etc:

  PlaySound("SystemExclamation", NULL, SND_ASYNC | SND_ALIAS);

But I leave that to you.  By the way, additional information on 
PlaySound can be found at:

  http://www.bcbdev.com/faqs/faq54.htm

Good luck!

-- 
Yoto Yotov
Re: Changing a PlaySound path name on the fly...
#1243
Author: Nicholas Gessler
Date: Sat, 11 Aug 2001 23:25
55 lines
3138 bytes
Thanks Yoto,

I'll try your approach below:

> Here's how your code may look like:
>
>   String FileName(WinDir);
>   FileName += "\\media\\jungle asterisk.wav";
>   PlaySound(FileName.c_str(), NULL, SND_ASYNC | SND_FILENAME);
>
> Note that your code assumes that this file exists.  However, on most
> systems (including mine), this file is not available.  A more correct
> approach is to use the user's default sounds such "SystemExclamation",
> "SystemQuestion", "SystemHand", etc:
>
>   PlaySound("SystemExclamation", NULL, SND_ASYNC | SND_ALIAS);

Yes, your point is well taken.  This silly application was intended to
gain/teach a little bit about playing wave files.  I calle it "wave harp."
It is an annoying little work that plays 64 noises in the Win98 media file
as you move the mouse around the window.

>   http://www.bcbdev.com/faqs/faq54.htm

Based on your previous recommendation, I independently came up with:

    // Fetch the windows directory
    char WinDir[MAX_PATH];

    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
       WinDir[MAX_PATH] = '\0';
       GetWindowsDirectory(WinDir,MAX_PATH);
       Form1->Edit1->Text = MAX_PATH;  // from which I see that MAX_PATH =
260
    }

I then go through a MouseOver event handler with 64 statements similar to
this:

        if (X == 10) PlaySound(strcat(WinDir,"\\media\\jungle
asterisk.wav"), "", SND_ASYNC);

This also works, though I realize that WinDir just keeps growing in size, so
it plays the first sound, the paths for the remaining sounds are too long
and are therefore ignored, and I get an error very soon because WinDir has
grown larger than 260.  I was looking for a simple way to concatenate the
path and file names.  I guess it will simply take a few lines to do so.  I
guess there's not much point in avoiding pasting all these lines in 64
times.  I understand these other problems and can find a way to work around
them.

Cheers,
Nick
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads