Parameters uType Specifies the sound type, as identified by an entry in the [sounds] section of the registry. This parameter can be one of the following values: Value Sound 0xFFFFFFFF Standard beep using the computer speaker MB_ICONASTERISK SystemAsterisk MB_ICONEXCLAMATION SystemExclamation MB_ICONHAND SystemHand MB_ICONQUESTION SystemQuestion MB_OK SystemDefault
楼上 的多虑了吧BOOL Beep( DWORD dwFreq, // sound frequency DWORD dwDuration // sound duration ); 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.
to lygfqy(风清扬) : 98下确实可以调用这个函数,但是确实不管用,喇叭不响。
Beep(1000,1000)是可行的, Beep(200,500)语法是没有错的,但是频率太低耳朵听不见 // beepDlg.cpp : implementation file //#include "stdafx.h" #include "beep.h" #include "beepDlg.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif///////////////////////////////////////////////////////////////////////////// // CBeepDlg dialogCBeepDlg::CBeepDlg(CWnd* pParent /*=NULL*/) : CDialog(CBeepDlg::IDD, pParent) { //{{AFX_DATA_INIT(CBeepDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }void CBeepDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CBeepDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP }BEGIN_MESSAGE_MAP(CBeepDlg, CDialog) //{{AFX_MSG_MAP(CBeepDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CBeepDlg message handlersBOOL CBeepDlg::OnInitDialog() { CDialog::OnInitDialog(); SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control }// If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework.void CBeepDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } }HCURSOR CBeepDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }void CBeepDlg::OnButton1() { Beep(1000,1000); }
UINT uType // sound type
);
Parameters
uType
Specifies the sound type, as identified by an entry in the [sounds] section of the registry. This parameter can be one of the following values: Value Sound
0xFFFFFFFF Standard beep using the computer speaker
MB_ICONASTERISK SystemAsterisk
MB_ICONEXCLAMATION SystemExclamation
MB_ICONHAND SystemHand
MB_ICONQUESTION SystemQuestion
MB_OK SystemDefault
的。
beep是让喇叭按指定的频率和时长发声,我甚至写了一个用beep来演奏音乐的程序,呵呵还满动听的。
MessageBeep是让声卡发声,而不是机箱上的蜂鸣器,声音是windows里规定的报错啦,提示信息啦什么的固定几个声音。
他的声明是这样的
BOOL MessageBeep(
UINT uType // sound type
);
参数是以下几个的其中一个,一看就明白了。
0xFFFFFFFF
MB_ICONASTERISK
MB_ICONEXCLAMATION
MB_ICONHAND
MB_ICONQUESTION
MB_OK
DWORD dwFreq, // sound frequency
DWORD dwDuration // sound duration
);
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.
98下确实可以调用这个函数,但是确实不管用,喇叭不响。
Beep(200,500)语法是没有错的,但是频率太低耳朵听不见
// beepDlg.cpp : implementation file
//#include "stdafx.h"
#include "beep.h"
#include "beepDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CBeepDlg dialogCBeepDlg::CBeepDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBeepDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBeepDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CBeepDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBeepDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CBeepDlg, CDialog)
//{{AFX_MSG_MAP(CBeepDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CBeepDlg message handlersBOOL CBeepDlg::OnInitDialog()
{
CDialog::OnInitDialog(); SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CBeepDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}HCURSOR CBeepDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CBeepDlg::OnButton1()
{
Beep(1000,1000);
}