VC++ Beep函数发不出音怎么办?

lulutong_ 2012-08-19 03:01:04
工程名称是Win32 console application;
#include <windows.h>
void main()
{
DWORD f=0x1b8;
DWORD t=1000;
Beep(f,t);
}
编译通过,运行不报错但无声音,求解。
...全文
1980 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-08-20
  • 打赏
  • 举报
回复
Speaker在主板上;不在声卡输出连接的喇叭上。

Beep Function

Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes.


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.
Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Muting and volume control have no effect on Beep; you will still hear the tone. To silence the tone, use the following commands:


net stop beep
sc config beep start= disabled

Terminal Services: The beep is redirected to the client.
Windows Me/98/95: On computers with a sound card, the function plays the default sound event. On computers without a sound card, the function plays the standard system beep.
Example Code [C++]
The following example demonstrates the use of this function.

Beep( 750, 300 );

Requirements
Client
Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.

Server
Requires Windows Server 2008, Windows Server 2003, Windows 2000 Server, or Windows NT Server.

Header
Declared in Winbase.h; include Windows.h.

Library
Use Kernel32.lib.

DLL
Requires Kernel32.dll.


See Also
Error Handling Functions
MessageBeep
Notifying the User



Send comments about this topic to Microsoft

Build date: 8/10/2007
赵4老师 2012-08-20
  • 打赏
  • 举报
回复
大多数笔记本主板无Speaker
lulutong_ 2012-08-20
  • 打赏
  • 举报
回复
“Muting and volume control have no effect on Beep; you will still hear the tone.”那就是笔记本主板木有Speaker了?[Quote=引用 7 楼 的回复:]
Speaker在主板上;不在声卡输出连接的喇叭上。

Beep Function

Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the soun……
[/Quote]
lulutong_ 2012-08-20
  • 打赏
  • 举报
回复
你的是笔记本的么?[Quote=引用 5 楼 的回复:]
我的机器没有问题
[/Quote]
lulutong_ 2012-08-20
  • 打赏
  • 举报
回复
我的是XP的,估计因为是笔记本的吧。这个真的很蛋疼。我93年的古董笔记本可以发音,但是只能发一个音调。[Quote=引用 3 楼 的回复:]
Beep() 函数本来是用于让 PC Speaker 发声的,在 XP 和 2000 下只要有 PC Speaker 都能很好地工作。
但是在 Win7 里它却让声卡发声,而且效果比 PC Speaker 烂(尤其是连续播放短促音的时候)。
如果 LZ 在 Win7 下,需要开启音箱才能听到声音。

PS: 要引用贴子内容请点贴子右下角的"引用"
[/Quote]
JinCraft 2012-08-19
  • 打赏
  • 举报
回复
笔记本应该不行的吧 至少我的不行 开机的时候没有台式机那种的滴的一声
Gloveing 2012-08-19
  • 打赏
  • 举报
回复
我的机器没有问题
JinCraft 2012-08-19
  • 打赏
  • 举报
回复
你用的笔记本吧 笔记本一般是没有这个喇叭的

一般播放声音的喇叭和你指的这个喇叭不是同一个

Beep调用的喇叭只能发出几种固定音调的声音,一般用来发出台式机开机自检的信号音
播放音乐的喇叭是播放波形声音的,播放的是声卡的声音,可以播放很多种音调叠加成的声音
wingzero520 2012-08-19
  • 打赏
  • 举报
回复
Beep() 函数本来是用于让 PC Speaker 发声的,在 XP 和 2000 下只要有 PC Speaker 都能很好地工作。
但是在 Win7 里它却让声卡发声,而且效果比 PC Speaker 烂(尤其是连续播放短促音的时候)。
如果 LZ 在 Win7 下,需要开启音箱才能听到声音。

PS: 要引用贴子内容请点贴子右下角的"引用"
lulutong_ 2012-08-19
  • 打赏
  • 举报
回复
加循环也没用的,因为根本就没有声音。
我的电脑本省可以播放音乐的,喇叭肯定没问题。
我是新手,不知道怎么回复别人的回复,所以一楼的这位我不知道怎么跟你直接交流了,麻烦哪位提示一下。
Gloveing 2012-08-19
  • 打赏
  • 举报
回复
加个循环吧,不然只出声一次:
#include <windows.h>
void main()
{
DWORD f=0x1b8;
DWORD t=1000;
while (1)
{
Beep(f,t);
}

}

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧