c++ - 为什么在 Windows 7 中调用 Beep 功能后听不到任何声音?

标签 c++ windows winapi audio beep

我有以下代码:

#include <windows.h>
#include <stdio.h>

int main(void)
{
        Beep(523, 500);
        Sleep(1000);
        return 0;
}

我正在使用 MinGW 和 Dev-C++ 编译它。我的问题是我听不到任何声音,尽管我没有收到错误消息。我有 Windows 7。有什么想法吗?

最佳答案

打开扬声器。如果它们已经打开,请调高音量。如果您的计算机上没有安装扬声器和声卡,请获取并安装它们,然后再次尝试运行该程序。

所有这些都需要从 Beep function 中听到任何信息在 Windows 7 上。It no longer plays sound from the built-in hardware system speaker.相反,声音会传递到用户 session 的默认声音设备。在标准的本地用户 session 中,这就是您的声卡。文档在“备注”部分解释了这一重要细节:

A long time ago, all PC computers shared a common 8254 programable interval timer chip for the generation of primitive sounds. The Beep function was written specifically to emit a beep on that piece of hardware.

On these older systems, muting and volume controls have no effect on Beep; you would still hear the tone. To silence the tone, you used the following commands:

net stop beep  
sc config beep start= disabled

Since then, sound cards have become standard equipment on almost all PC computers. As sound cards became more common, manufacturers began to remove the old timer chip from computers. The chips were also excluded from the design of server computers. The result is that Beep did not work on all computers without the chip. This was okay because most developers had moved on to calling the MessageBeep function that uses whatever is the default sound device instead of the 8254 chip.

Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.

In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client.

关于c++ - 为什么在 Windows 7 中调用 Beep 功能后听不到任何声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10266599/

相关文章:

c++ - c++0x 中的返回值是否将通过右值引用传递?

c# - 如何快速而可靠地确定是否安装了 Visual C++ 2013 Runtime

c++ - 如何将 FileDialog 限制到特定路径

c++ - 使用可变参数模板获取/发布的 RAII 模式

c++ - Qt- Qlist 检查包含自定义类

c++ - 函数 "int (*function())[10];"是什么意思?

java - 即使在用户注销后仍在 Windows 中运行 Java 进程

c# - 如何调查 Process.Start() 失败?

C++ Windows 凭据提供程序进度屏幕

c++ - ReadFile() 输出到 WinAPI 编辑对话框