Cool Beep!

NoBug 2000-03-09 04:08:00
我想计算机中的扬声器已经快被我们遗忘了吧?不过,今天我写了一个关于控制NT下的扬声器的示例程序,虽然很短,但很有趣,大家有空过来看看!

// Beep.cpp : Defines the entry point for the console application.
// Author : NoBug
// Data : 00.3.9
// This program will run only on NT

#include <Windows.h>
#include <Winioctl.h>
#include <Stdio.h>


#define DeviceName "\\Device\\Beep"
#define SymbolicName "DosBeep"

// copy from NT DDK

#define IOCTL_BEEP_SET CTL_CODE(FILE_DEVICE_BEEP, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define BEEP_FREQUENCY_MINIMUM 0x25
#define BEEP_FREQUENCY_MAXIMUM 0x7FFF

typedef struct _BEEP_SET_PARAMETERS {
ULONG Frequency;
ULONG Duration;
} BEEP_SET_PARAMETERS, *PBEEP_SET_PARAMETERS;



int main(int argc, char* argv[])
{
BOOL bReturn;
HANDLE hBeep;
CHAR szFileName[MAX_PATH];
int iIndex;
DWORD dwReturn;

OSVERSIONINFO ver;
BEEP_SET_PARAMETERS param;

ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&ver);
if(ver.dwPlatformId!=VER_PLATFORM_WIN32_NT)
{
MessageBox(NULL,"This program must run on NT!","",MB_OK);
return 0;
}

// Create a symbolic object to beep device
// so I can access this device in user mode.
bReturn = DefineDosDevice(DDD_RAW_TARGET_PATH, SymbolicName, DeviceName);
if(bReturn==FALSE)
{
MessageBox(NULL,"DefineDosDevice Error!","",MB_OK);
return 0;
}

sprintf(szFileName,"\\\\.\\%s",SymbolicName);

hBeep = CreateFile(szFileName,
0,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);

if(hBeep==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,"CreateFile Error!","",MB_OK);
return 0;
}

for(iIndex=1;iIndex<50;iIndex++)
{
param.Duration = 100;
param.Frequency = 2000 + iIndex*50;
// send device io control IRP to beep device
DeviceIoControl(hBeep,
IOCTL_BEEP_SET,
(LPVOID)¶m,
sizeof(BEEP_SET_PARAMETERS),
NULL,
0,
&dwReturn,
NULL);
// sleep
Sleep(param.Duration);
}

CloseHandle(hBeep);
// remove the symbolic object
DefineDosDevice(DDD_REMOVE_DEFINITION,
SymbolicName,
DeviceName);
return 0;
}

...全文
225 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn2000 2000-03-20
  • 打赏
  • 举报
回复
OK
6 , chunks.zip<br>This will open a file and read it in "Chunks" of a selected file.<END><br>7 , logging.zip<br>This is a bas that will log installation procedures so the file can be removed later.<END><br>8 , savetree.zip<br>This will save the info in a Tree View. "This technique allows a program to save hierarchical information like the data in a TreeView in a way that is easy to understand."<END><br>11 , OLE.zip<br>Demonstrates the use of OLE.<END><br>12 , gradtxt2.zip<br>"A program for drawing horizontal, rectangular or spherical gradient texts."<END><br>13 , sweepgl.zip<br>This example greatly demonstrates how to use OpenGL in Visual Basic.<END><br>15 , drawdemo.zip<br>This is an excellent example of how to make a paint program with a few extras.<END><br>16 , cube.zip<br>This example demonstrates how to rotate a cube in visual basic.<END><br>17 , sprite1.zip<br>This is an Excellent example on how to use sprites in your program.<END><br>18 , charcreate.zip<br>This is an example of how to assign "characters" to differant pictureboxes. This would be a good starting point for VB game developers.<END><br>19 , breakthrough.zip<br>This demonstrates a simple game in Visual Basic. An excellent example.<END><br>26 , openlib.zip<br>These are the type libs that go with OpenGL. This is used to make 3D text.<END><br>27 , basMath.zip<br>This module contains functions for various math equations. <END><br>28 , calc.zip<br>This is a basic calculator written in Visual Basic.<END><br>29 , stopwatch.zip<br>This shows how to count off time in a Stop Watch format.<END><br>31 , taskhide.zip<br>This will hide your application from the taskbar, Alt+Tab, and Alt+Ctrl+Del.<END><br>32 , newbie.zip<br>This is a nicely done help file for programmers that are new to Visual Basic.<END><br>33 , vbfaq.zip<br>This is AOL's PC Dev Visual Basic FAQ. This is an excellent starting point for begginners.<END><br>34 , Bas.zip<br>it is very good modual for activex<END><br>35, paraviasource.zip<br>This is

6,849

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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