Solved

How to turn on/off  the pc speaker in W2K?

Posted on 2002-06-23
7
341 Views
Last Modified: 2010-04-04
Hi all,
This codes work fine with win98, but can't work with Win2000, How to change it? (Please don't just tell me a component, I need the source)


 if BeepOn then        //BeepOn is a logic flag
 begin
 asm
   mov al,3            //turn on the pc speaker
   out $61,al
   mov al,$0B6
   out $43,al
   mov al,200
   out $42,al
   mov al,20
   out $42,al
 end;
 end
 else
 begin
 asm
  mov al,0            //turn off the pc speaker
  out $61,al
 end;
 end;
0
Comment
Question by:xbbin
7 Comments
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
hello

  I think you can't do that with win2000/xp, cuz it's not allowed you to direct access the hardware

the code which using assemply with ports, doesn't work in any version based on NT, i'm not sure with that also with the PC speaker, but i think it's the same cuz u r using assembly code to access the hardware
0
 

Author Comment

by:xbbin
Comment Utility
Hi,
I just want to turn on/off the pc speaker, How to do that without assembly code?
0
 
LVL 2

Expert Comment

by:Tasomia
Comment Utility
Try this:

// Disable Enable:
procedure TForm1.Button1Click(Sender: TObject);
begin
  SystemParametersInfo(SPI_SETBEEP,0,NIL,SPIF_SENDWININICHANGE);
end;


// Enable Beep:
procedure TForm1.Button2Click(Sender: TObject);
begin
  SystemParametersInfo(SPI_SETBEEP,1,NIL,SPIF_SENDWININICHANGE);
end;
 
tas
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:xbbin
Comment Utility
Hi Tasomia,
Not have any sound at all.
0
 
LVL 2

Accepted Solution

by:
freshman3k earned 50 total points
Comment Utility
Hello!

1)Download the following component:
http://www.torry.net/vcl/system/portaccess/smport.zip

2)Install the component

3)Place the component on the form

4)Put the following code in the formshow event:
SmallPort->OpenDriver;

5)Put the following code in the formclose event:
SmallPort->CloseDriver;

6)Use the following code to turn the pc speaker off:
SmallPort->SpeakerOff;

7)Use the following code to enable the pc and beep the speaker with a specified tone:
SmallPort->SpeakerOn(Tone);

8)Use the following code to enable the pc and beep the speaker with a specified Freq and delay:
SmallPort->Sound(Freq,Delay);

And This will work in all versions of windows.

>Please don't just tell me a component, I need the source

There is no way to accomplish that you want in winnt/win2k/winxp with just using assembly and not using drivers.

This component is free and includes sources for the drivers and the component.  

Good Luck! :-)
0
 

Author Comment

by:xbbin
Comment Utility
Hi freshman,
Why can't install it on Delphi3? The compiler say: SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START and SERVICE_ERROR_NORMAL are undeclared identifier.

(Should I need to declared some unit on the "use" section??)

Delphi4 not have this problem.

Regards, bin
0
 
LVL 2

Expert Comment

by:freshman3k
Comment Utility
Hello bin,

Try Putting 'WinSvc.pas' unit in the implementation's uses
 

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now