Delphi 在 SysUtils 单元定义 Beep 方法, 可以发出一个声音, 一般用于提醒和调试.
Beep 其实是调用的 API 函数: MessageBeep(MB_OK);
MessageBeep 有下面几种用法可以调用几种不同的声音文件:
MessageBeep(MB_OK); MessageBeep(MB_ICONHAND); MessageBeep(MB_ICONQUESTION); {这个不响, 不知道为什么} MessageBeep(MB_ICONEXCLAMATION); MessageBeep(MB_ICONASTERISK); MessageBeep($FFFFFFFF); {同 MessageBeep(MB_OK);}
Beep 同时也是一个 API 函数, 它可以指定声音的高度和长度; 因为和 SysUtils.Beep 重名了, 所以应该这样调用:
Windows.Beep(音高, 长度);
譬如: Windows.Beep(440, 2000); 会把一个国际标准音(440HZ)演奏 2 秒钟.
另外第一个参数的取值范围是: $25 - $7FFFF.
音 | 频率 | 编号 |
---|---|---|
C#0 | 34.65 | 25 |
D0 | 36.71 | 26 |
D#0 | 38.89 | 27 |
E0 | 41.20 | 28 |
F0 | 43.65 | 29 |
F#0 | 46.25 | 30 |
G0 | 49.00 | 31 |
G#0 | 51.91 | 32 |
A0 | 55.00 | 33 |
A#0 | 58.27 | 34 |
B0 | 61.73 | 35 |
C1 | 65.41 | 36 |
C#1 | 69.30 | 37 |
D1 | 73.42 | 38 |
D#1 | 77.78 | 39 |
E1 | 82.41 | 40 |
F1 | 87.31 | 41 |
F#1 | 92.50 | 42 |
G1 | 98.00 | 43 |
G#1 | 103.83 | 44 |
A1 | 110.00 | 45 |
A#1 | 116.54 | 46 |
B1 | 123.47 | 47 |
C2 | 130.81 | 48 |
C#2 | 138.59 | 49 |
D2 | 146.83 | 50 |
D#2 | 155.56 | 51 |
E2 | 164.81 | 52 |
F2 | 174.61 | 53 |
F#2 | 185.00 | 54 |
G2 | 196.00 | 55 |
G#2 | 207.65 | 56 |
A2 | 220.00 | 57 |
A#2 | 233.08 | 58 |
B2 | 246.94 | 59 |
C3 | 261.63 | 60 |
C#3 | 277.18 | 61 |
D3 | 293.66 | 62 |
D#3 | 311.13 | 63 |
E3 | 329.63 | 64 |
F3 | 349.23 | 65 |
F#3 | 369.99 | 66 |
G3 | 391.99 | 67 |
G#3 | 415.30 | 68 |
A3 | 440.00 | 69 |
A#3 | 466.16 | 70 |
B3 | 493.88 | 71 |
C4 | 523.25 | 72 |
C#4 | 554.36 | 73 |
D4 | 587.33 | 74 |
D#4 | 622.25 | 75 |
E4 | 659.25 | 76 |
F4 | 698.46 | 77 |
F#4 | 739.99 | 78 |
G4 | 783.99 | 79 |
G#4 | 830.61 | 80 |
A4 | 880.00 | 81 |
A#4 | 932.33 | 82 |
B4 | 987.77 | 83 |
C5 | 1046.50 | 84 |
C#5 | 1108.73 | 85 |
D5 | 1174.66 | 86 |
D#5 | 1244.51 | 87 |
E5 | 1318.51 | 88 |
F5 | 1396.91 | 89 |
F#5 | 1479.98 | 90 |
G5 | 1567.98 | 91 |
G#5 | 1661.21 | 92 |
A5 | 1760.00 | 93 |
A#5 | 1864.65 | 94 |
B5 | 1975.33 | 95 |
C6 | 2093.00 | 96 |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); const t = 800; begin Windows.Beep(330, t); Windows.Beep(392, t); Windows.Beep(262, t*2); Windows.Beep(294, t); Windows.Beep(330, t); Windows.Beep(196, t*2); Windows.Beep(262, t); Windows.Beep(294, t); Windows.Beep(330, t); Windows.Beep(392, t); Windows.Beep(294, t*4); end; end.