不是吧哥哥们,发个声音就要我用Direct?
这,太小题大做了吧,有没有简单的一个函数啊?
最简单的basic里都有,vc里不会这样一个函数都没有吧?

解决方案 »

  1.   

    复杂一点的用PlaySound()播放wav文件
      

  2.   

    是要机箱的speaker发声(不通过声卡)吧,playsound不行的
      

  3.   

    那可以考虑PlaySound(),建议用资源代替wav文件
      

  4.   

    那可以用PlaySound(),建议用资源代替wav文件
      

  5.   

    MSDN里说:Beep
    The Beep function generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes. BOOL Beep(
      DWORD dwFreq,      // sound frequency
      DWORD dwDuration   // sound duration
    );
    Parameters
    dwFreq 
    Windows NT/ 2000: [in] Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF). 
    dwDuration 
    Windows NT/ 2000: [in] Specifies the duration, in milliseconds, of the sound. 
    Return Values
    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. Res
    Windows 95: The Beep function ignores the dwFreq and dwDuration parameters. 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.Requirements 
      Windows NT/2000: Requires Windows NT 3.1 or later.
      Windows 95/98: Requires Windows 95 or later.
      Header: Declared in Winbase.h; include Windows.h.
      Library: Use Kernel32.lib.See Also
    Error Handling Overview, Error Handling Functions, MessageBeep 95以上就可以用Beep()这个函数了,长短频率随你定
      

  6.   

    你没看清楚
    Res
    Windows 95: The Beep function ignores the dwFreq and dwDuration parameters. 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.
    9x系列无法指定频率和时间
      

  7.   

    小程序不想用wav文件,把声音放在资源里也行啊,不过我不会
    谁能教我?可以再加分的,决不食言!
      

  8.   

    不好意思,要指定任意频率PlaySound不行的,可以用底层音频函数(在内存中根据频率准备合适的缓冲区)或DirectSound,可能还有更底层的方法或控件可用,在网上找一下吧
      

  9.   

    messagebeep
    最简单也是最实用如果不想做播放器的话
      

  10.   

    waveInXXX、waveOutXXX,用wave打头的一堆东东试试。
      

  11.   

    messagebeep不能指定长短频率
    waveXXX都要用到audio device,好麻烦
    我只是想有那么“嘀”的一声,但不要系统的声音,真的没有简单的办法么?
      

  12.   

    写点asm 程序,嵌入在C中间是不是就可以了呢。呵呵。
    直接用系统的中断
      

  13.   

    WIN9X下确实没有这类函数我用汇编写了一个小程序,只支持WIN9X,不支持WIN2000
    WIN2000可以用BEEP()
    void AsmSound(WORD Freq)
    {
    LARGE_INTEGER frequency;
    QueryPerformanceFrequency(&frequency);

    Freq=(unsigned short)(((double)frequency.QuadPart)/Freq);//counter number
    __asm
    {
    mov aL,0xB6
    out 0x43,al
    mov ax,Freq
    out 0x42,al
    mov al, ah
    out 0x42,al
    in  al,0x61
    or  al,3
    out 0x61,al
    }
    }void AsmNoSound(void)
    {
    __asm
    {
    in al,0x61
    and aL, 0xfc
    out 0x61, aL
    }
    }
     
    很少这么用了?
      

  14.   

    dahua(大华) !说话要算数!!:)
      

  15.   

    呵呵,当然要算数的,放心放心,
    好人做到底请问如何判断是nt还是9x?
      

  16.   

    谁能告诉我如何判断是运行的系统nt还是9x?
      

  17.   

    http://ygyuan.go.163.com/ 
    http://ygyuan.3322.net/有动态链接库,可以在 Win9x 下发出不同频率的声音.有例程.
      

  18.   

    非常简单,使用MessageBeep();
    具体的看看msdn!
      

  19.   

    void BeepSound(UINT freq,float dura)
    {
    UINT frequency = freq;    _outp(0x43, (char)0xb6);             if (frequency > 0)          
            frequency = (unsigned) (1193180L/frequency);    _outp(0x42, (char)frequency);
        _outp(0x42, (char)(frequency >> 8)); for (UINT i=0;i<(100000*dura);i++)
    _outp(0x61, (char)(_inp(0x61) | 0x3));
       
    _outp(0x61, (char)(_inp(0x61) & ~0x3));   
    }
      

  20.   

    用Beep.
    BOOL Beep(
      DWORD dwFreq,      // sound frequency
      DWORD dwDuration   // sound duration
    );
      

  21.   

    我有Delphi下PcSpeaker发声的控件。
      

  22.   

    lily311() 说的对用_outp来发声
      

  23.   

    win95/98下用beep或是MessageBeep都不行,但win95/98下可用_outp我的方法是:
    /////////////////////////////////////////////////////////////////////////////////////////// // 函数名: Sound
    // 编写者: 
    // 参考资料: 
    // 功   能: 
    // 输入参数: nFreq:嗽叭鸣叫频率 nTimeOut:嗽叭鸣叫持续时间
    // 输出参数: 
    void Sound(const unsigned long& nFreq,const unsigned long& nTimeOut)
    {
    assert(nFreq > 0 && nTimeOut > 0); unsigned  uStatus,uRatio,uLobyte,uHibyte;
    uStatus=_inp(0x61);
    _outp(0x43,0xb6);
    uRatio = (unsigned)(1193180L/nFreq);//发声速率

    uLobyte=uRatio&0xff;//速率低字节
    _outp(0x42,uLobyte);

    uHibyte=(uRatio>>8)&0xff;//速率高字节
    _outp(0x42,uHibyte);
    _outp(0x61,(uStatus|3));//开始发声

    Sleep(nTimeOut);

    _outp(0x61,(uStatus&~3));
    }