费玉清时代的经典歌曲:WinCE下 打开与关闭蓝牙
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 11:05:32
WinCE下打开与关闭蓝牙
在WinCE下打开与关闭蓝牙非常的简单(只是一个API的调用);WinCE下打开与关闭蓝牙及判断蓝牙状态所用API如下:
1.状态定义枚举
enum BTH_RADIO_MODE {
BTH_POWER_OFF,
BTH_CONNECTABLE,
BTH_DISCOVERABLE
};
2.获取状态
int BthGetMode(
DWORD* pdwMode
);
3.设置蓝牙状态
int BthSetMode(
DWORD dwMode
);
如我们要获取当前蓝牙的状态只需要用如下代码:
#include "bthutil.h"
void CTestWinCEDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
int nRet;
DWORD dwMode;
nRet = BthGetMode( &dwMode );
//判断获取状态是否成功
if ( nRet == ERROR_SUCCESS )
{
if ( dwMode == BTH_CONNECTABLE )
{
AfxMessageBox( _T("当前蓝牙为开启") );
}else if ( dwMode == BTH_POWER_OFF )
{
AfxMessageBox( _T("当前蓝牙为关闭") );
}
}
}
而我们要开启蓝牙只需要如下代码:
#include "bthutil.h"
void CTesttWinCEDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
int nRet;
nRet = BthSetMode( BTH_CONNECTABLE );
//判断是否成功
if ( nRet == ERROR_SUCCESS )
{
AfxMessageBox( _T("蓝牙开启成功") );
}else
{
AfxMessageBox( _T("蓝牙开启失败") );
}
}
与开启蓝牙一样,闭关蓝牙只需要如下代码:
#include "bthutil.h"
void CTesttWinCEDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
int nRet;
nRet = BthSetMode( BTH_POWER_OFF );
//判断是否成功
if ( nRet == ERROR_SUCCESS )
{
AfxMessageBox( _T("蓝牙关闭成功") );
}else
{
AfxMessageBox( _T("蓝牙关闭失败") );
}
}
当然上面的代码是否能编译通与是否能成功执行还与你的SDK及设置有关,比如在本人的WinCE50Emulator SDK下就没有蓝牙支持,所以出现了'bthutil.h': No such file or directory错