(1)用 Beep函数 ,要 包含 头文件 #include <windows.h>
(2)Beep函数有2个参数数橡,第一个参数是声音的频率,第二个参数是所发声音长度毫秒
Beep(523,500) -- 中音 多,发0.5秒即500毫秒
Beep(587,500) -- 中音 来
Beep(659,500) -- 中音 米
Beep(698,500) -- 中音 法
Beep(784,500)-- 中音 少
Beep(880,500)-- 中音 拉
Beep(980,500)-- 中音 梯
Beep(1060,500)-- 高音 多
(3)休止符 用 Sleep(时间,单位毫秒)
如果 一拍用500毫秒,休息一拍 则为 Sleep(500)
d出抬棺音乐,则要按曲子一个薯升旁音符一个音符地去写。
例如:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main () {
int t1=500,t05=250,t15=750
Beep(523,t1)Beep(587,t1)Beep(659,t1)
Beep(698,t1)Beep(784,t1)Beep(880,t1)
Beep(980,t1)Beep(1060,t1)
Sleep(t1)
Beep(523,t05)Beep(587,t05)Beep(659,t05)
Beep(698,t05)Beep(784,t05)
return(0)
}
曲子: 1234567高1 发音各500毫秒,停500毫秒, 12345 发音各250毫秒。
不需要头文件,直接调用即可。MSDN中是这样定义的:
BOOL WINAPI Beep(
__in DWORD dwFreq,
__in DWORD dwDuration
)
Parameters
dwFreq
The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
Windows Me/98/携闭95: The Beep function ignores this parameter.
dwDuration
The duration of the sound, in milliseconds.
Windows Me/98/95: The Beep function ignores this parameter.
第一个参数是频率,其值为拿腔37到32767,单位为Hz
第二个参数是持续时间,单位为毫秒辩敏裂,1秒=1000毫秒。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)