您的位置:首页 > 其它

WIN32 API之硬件控制

2006-09-01 17:46 267 查看
一、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.

Remarks
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
Samples:

void CAboutDlg::OnButton1()
{
// TODO: Add your control notification handler code here
// Beep 用于生成简单的声音

Beep(1000,1); // 发一次1000频率的声音

}

二、ClipCursor(CONST RECT *lpRect)、GetClipCursor(LPRECT lpRect)

设置鼠标活动范围,取得鼠标活动范围。

Samples:

void CAboutDlg::OnButton1()
{
// TODO: Add your control notification handler code here
// ActivateKeyboardLayout 激活一个新的键盘布局。键盘布局定义了按键在一种物理性键盘上的位置与含义
RECT rt;
rt.left = 30;
rt.right = 300;
rt.top = 20;
rt.bottom = 200;
ClipCursor(&rt); // 你的光标只能在固定区域啦。
GetClipCursor(LPRECT lpRect)
}

void CAboutDlg::OnButton2()
{
// TODO: Add your control notification handler code here
RECT rt;
GetClipCursor(&rt);
CString str;
str.Format(TEXT("Cursor is in right = %d buttom = %d"),rt.right,rt.bottom );
MessageBox(str);
}

建议先调用GetClipCursor()将用户默认的鼠标活动范围取出到全局变量中。之后调用ClipCursor()设置鼠标活动范围。最后再调用一次ClipCursor()恢复用户默认的鼠标活动范围。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: