关于PC喇叭(50分)

  • 主题发起人 主题发起人 stnana
  • 开始时间 开始时间
S

stnana

Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI中如果要使用PC喇叭发声要怎么做?PC喇叭发的声音有几,参数是什么?
 
beep or &nbsp;messagebeep<br>自己在帮助里查一下怎么用
 
messagebeep();<br><br>参数:<br>0xFFFFFFFF Standard beep using the computer speaker<br>MB_ICONASTERISK SystemAsterisk<br>MB_ICONEXCLAMATION SystemExclamation<br>MB_ICONHAND SystemHand<br>MB_ICONQUESTION SystemQuestion<br>MB_OK SystemDefault<br><br>
 
nt下可以用Beep(频率,毫秒)
 
以前帮朋友在网上找到的:<br>(只是部分代码)<br><br>{---------------------------------_GetPort--------------------------------------}<br>function _GetPort(address:word):word;<br>var<br>&nbsp;bValue: byte;<br>begin<br>&nbsp; asm<br>&nbsp; &nbsp; mov dx, address<br>&nbsp; &nbsp; in al, dx<br>&nbsp; &nbsp; mov bValue, al<br>&nbsp; end;<br>&nbsp; Result := bValue;<br>end; &nbsp; { _GetPort }<br><br><br>{----------------------------------_SetPort--------------------------------------}<br>procedure _SetPort(address, Value:Word);<br>var<br>&nbsp;bValue: byte;<br>begin<br>&nbsp; bValue := Trunc(Value and 255);<br>&nbsp; asm<br>&nbsp; &nbsp; mov dx, address<br>&nbsp; &nbsp; mov al, bValue<br>&nbsp; &nbsp; out dx, al<br>&nbsp; end;<br>end; &nbsp; { _SetPort }<br><br><br>{----------------------------------StartBeep--------------------------------------}<br>procedure StartBeep(Freq : Word);<br>var<br>&nbsp; B: Byte;<br>begin<br>&nbsp; if (Freq &gt;= LOW_FREQ) and (Freq &lt;= HIGH_FREQ)<br>&nbsp; then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Freq := Word(1193181 div LongInt(Freq));<br>&nbsp; &nbsp; &nbsp; B := Byte(_GetPort($61));<br>&nbsp; &nbsp; &nbsp; if (B and 3) = 0<br>&nbsp; &nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _SetPort($61, Word(B or 3));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _SetPort($43, $B6);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; _SetPort($42, Freq);<br>&nbsp; &nbsp; &nbsp; _SetPort($42, Freq shr 8);<br>&nbsp; &nbsp; end;<br>end; { StartBeep }<br><br><br><br>{------------------------------StopBeep----------------------------------------}<br>procedure StopBeep;<br>var<br>&nbsp;Value: Word;<br>begin<br>&nbsp; Value := _GetPort($61) and $FC;<br>&nbsp; _SetPort($61, Value);<br>end; &nbsp;{ StopBeep }<br><br><br>用法:<br>&nbsp; StartBeep(Tone); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Tone为频率<br>&nbsp; StartTime:=GetTickCount;<br>&nbsp; while ( (GetTickCount - StartTime) &lt; LongInt(MSecs) ) do &nbsp;//MSecs为响声长度(毫秒)<br>&nbsp; &nbsp; Application.ProcessMessages;<br>&nbsp; StopBeep;<br><br>*我自己没试过
 
漏了这两个常量:<br>&nbsp;LOW_FREQ &nbsp; = 40;<br>&nbsp;HIGH_FREQ &nbsp;= 5000;<br>
 
<br>&nbsp; beep;和<br>&nbsp; messageBeep(0);是一样的<br><br>&nbsp; 用WinApi &nbsp;在uses单元中加 &nbsp;MnSystem<br>&nbsp; PlaySound(Pchar(c:/windows/system/ &nbsp; .wav),0,snd_Async);<br>&nbsp; <br>也可以...... <br>
 
beep 不是,试一下就知道了。<br>原来有 sound 函数,现在没有了,用汇编可以,<br>但 nt 下怎么办?
 
不要用MessageBeep,应该用Beep,而且不是Delphi的Beep(SysUtils),是<br>Windows的Beep<br>Windows.Beep<br>下面是MSDN的说明:<br><br>BOOL Beep(<br>&nbsp; DWORD dwFreq, &nbsp; &nbsp; &nbsp;// sound frequency, in hertz<br>&nbsp; DWORD dwDuration &nbsp; // sound duration, in milliseconds<br>);<br>&nbsp;<br>Parameters<br>dwFreq <br>Windows NT: Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF). <br>dwDuration <br>Windows NT: Specifies the duration, in milliseconds, of the sound. <br>
 
对了,想起来了,是这样的,呵呵,没试过,<br>98 是不行的。
 
多人接受答案了。
 
后退
顶部