Beep sound

I know how to do beeps with various frequencies and durations in Visual Basic and the code was working on windows 3.1 and 95.

However, I feel it is more difficult in Delphi (should
be better than Visual Basic):

People said we may use Windows.Beep(frequency, duration)
in Windows NT (but not in Windows 3.1, I think), I have
tried to use it in Windows 95. It was working anyway but
was only a simple beep. When I change the frequency from
99 to 999999999 and change the duration from 99 to
999999999, the sounds remained the same!

Can you give me the right code for that (better for both
NT and 95)?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 You cannot generate different beeps in win95, as you can in NT, with the Beep call. As the Delphi help puts it:

Windows 95:
The Beep function ignores the dwFreq and dwDuration parameters. On computers with a sound card, the function plays the default sound event. On computers without a sound card, the function plays the standard system beep.

  i.e. Win95 ignores all parameters you enter into the Beep Command and just plays a simple beep. You might try MessageBeep instead, since this allows you to play several of the sounds in the windows registry such as SystemAsterisk and SystemExclamation. The info for this is in Delphi help, or I'll mail it to you if you want/require.

Hope this helps, Steven.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zhuhailAuthor Commented:
Thank you for your help.

You are right...that may not wrok in Win95 and I want you give me a right code :-)
Perhaps we can do beeps with designed frequency and duration in Win95 by calling API functions. That is what I did in Visual Basic....Or, do you think Win95 not supports the API functions for beep sound anymore? Can we still call such API functions of 16 bit from Win95?

OK I've just had a bit of a play with Beeps and this is the score:

There is a Delphi Beep Command Defined in SysUtils. If you have SysUtils in your Uses clause then Calling Beep will call this function. This function takes no parameters and if you try and put any in the call you will get an error. This function makes a simple beep sound using the internal speaker.

There is also an API call Beep. This call takes two parameters and can only be called directly if you remove SysUtils from the Uses clause, (otherwise you are calling the Delphi Beep function). The previous comments about this Beep command in win95 still stand. I don't have NT so I can't test what happens, but in 95 the API Beep function plays the Default Sound Wave, or a simple beep if no sound card is installed.

  I'm afraid I can't help you concerning 16 bit technology, it's out of my scope of knowledge, however I can tell you with some certainty that using the beep command in Win95 will never produce more than the one simple boring beep.

  Why do you need this functionality?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

zhuhailAuthor Commented:

I am so sad when I reading your comment :-(
This is the first thing I found that Win3.1 better then Win95.

Why I need such beeps? In Visual Basic, using such beeps, I made some very simple, but nice music in a game which is written under Win3.1 (without the sound card) but stil works under Win95.

 The thing about the Beep command is that it is only really intended for use as a warning sound (It is included as part of the Error processing functions). I don't know what sort of code was generated by Visual Basic such that your Application ported from 3.1 to 95 but I can only presume that it doesn't use the API Beep function. I havn't come accross a call that will allow the sort of wave generation that you are looking for in Win95, if it is possible then I suspect that it will require a lot of fiddly code and I don't know how it's done I'm afraid. I would stick to using sampled sounds for your games applications (Investigate the PlaySound API Call).
  Sorry to be so negative, feel free to reject this answer if you feel someone else might have a more satisfying answer for you.

Hi zhuhail here is keksperte

don't beleave them if they say impossible.

here is my solution:

   This is a workaround to create some tones other than the BEEP in Delphi
   (and other IDE's).  It's not DELPHI but it works, is flexible and it's free.

1. Create a link from the good old QBASIC.EXE and move it to the C:\tmp DIR
    and name it BEEPER
   (You will find QB in the C:\WIN95\Command or C:\WINNT\System32 Dir.)

   Enter on the programtab the comandline
     C:\WIN\COMMAND\QBASIC.EXE /RUN C:\tmp\MoreBeep.bas
   for the workingdir
   Also you can use a very small font (see fonttab, Sysfont 2x4)
   On screentab select standard window with restore params on restart so that the last
   windowposition will be saved

2. Create with the NOTEPAD or directly in QBASIC the following BasicCode:

   PLAY "MBT180o2P2P8L16CEGL8>CP64"
   WHILE PLAY(0) > 0: WEND
   rem 4 more help on PLAY press F1-Button or ALT+H in QB

   Save this code as 'MoreBeep.bas'

3. Create a new delphi project with a button.

4. Define in the ButtonClick procedure the following command:

   procedure TForm1.Button1Click(Sender: TObject);
     ShellExecute(Application.Handle, nil, 'Beeper', '', 'C:\tmp', SW_SHOW);

5. Compile the project and run. On Click you will hear the hevently sound on the speaker.

6. To hide the QB-Window you can use on WINNT the SW_SHOWMINIMIZED command     in the above ClickProcedure. On WIN95 it seams that the only way is to put the window
   near the border or under the TASK-BAR so that you can't see it at runtime.

So, that's it. I hope you'll become a great musican.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.