There is a interesting function which can play a System sound.
First let's see the WinAPI.
//声明: MessageBeep( uType: UINT {参数是个常数; 根据不同的常数发出不同的声音, 也就是调用了不同的 wav} ): BOOL; //参数 uType 可选值: MB_OK = 0; MB_ICONHAND = 16; MB_ICONQUESTION = 32; MB_ICONEXCLAMATION = 48; MB_ICONASTERISK = 64; //举例, 下面代码会发出错误警告 begin MessageBeep(16); end; //另外 Delphi 的 Beep 方法在 SysUtils 单元是这样实现的: procedure Beep; begin MessageBeep(0); end;
If you wana beep in your console program. You can use it like following.
1 #include <Windows.h> 2 3 int _tmain(int argc, _TCHAR* argv[]) 4 { 5 for( UINT i = 0; i < 100; i ++) { 6 MessageBeep(i); 7 Sleep(1000); 8 } 9 return 0; 10 }
Well, Running it, it will beep differently in every second. Thank you!