Procedure pcBeep(nFreq,nDura: Word); //pc喇叭发声
var
VerInfo: TOSVersionInfo;
nStart: DWord;
begin
VerInfo.dwOSVersionInfoSize := SizeOf(VerInfo);
GetVersionEx(VerInfo);
if VerInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
Windows.Beep(nFreq, nDura)
else
begin
Asm
push bx
in al,$61
mov bl,al
and al,3
jne @@Skip
mov al,bl
or al,3
out $61,al
mov al,$b6
out $43,al
@@Skip:
mov ax,nFreq
out $42,al
mov al,ah
out $42,al
pop bx
end;
nStart:=GetTickCount;
repeat
Application.ProcessMessages;
Until GetTickCount > nStart + nDura;
asm
IN AL,$61
AND AL,$FC
OUT $61,AL
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
pcBeep(300,3000);
end;