// DlgBlueToothExc.cpp : implementation file
//
#include "stdafx.h"
#include "BlueToothExc.h"
#include "DlgDataShow.h"
#include "DlgBlueToothExc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CDlgBlueToothExc dialog
CDlgBlueToothExc::CDlgBlueToothExc(CWnd* pParent /*=NULL*/)
: CDialog(CDlgBlueToothExc::IDD, pParent)
, m_pHwCOM ( NULL )
, m_hThread ( NULL )
, m_dwThreadID ( 0 )
, m_hEvtEndThread ( NULL )
, m_hEvtSendDataReq ( NULL )
, m_nBytesForSending ( 0 )
, m_bNoteBeCleared ( FALSE )
, m_bShowCurve(FALSE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
memset ( m_DataForSending, 0, sizeof(m_DataForSending) );
DeleteFile ( _T("c:\\bthdebug.dat") );
}
void CDlgBlueToothExc::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDlgBlueToothExc, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_ScanBluetoothDevice, &CDlgBlueToothExc::OnBnClickedButtonScanbluetoothdevice)
ON_LBN_DBLCLK(IDC_LIST_NearbyBthDev, &CDlgBlueToothExc::OnLbnDblclkListNearbybthdev)
ON_BN_CLICKED(IDC_BUTTON_Test, &CDlgBlueToothExc::OnBnClickedButtonTest)
ON_BN_CLICKED(IDC_BUTTON_Enumerate, &CDlgBlueToothExc::OnBnClickedButtonEnumerate)
ON_BN_CLICKED(IDC_BUTTON_RequestAuthenticate, &CDlgBlueToothExc::OnBnClickedButtonRequestauthenticate)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_Connect, &CDlgBlueToothExc::OnBnClickedButtonConnect)
ON_BN_CLICKED(IDC_BUTTON_Disconnect, &CDlgBlueToothExc::OnBnClickedButtonDisconnect)
ON_BN_CLICKED(IDC_BUTTON_Send, &CDlgBlueToothExc::OnBnClickedButtonSend)
ON_BN_CLICKED(IDC_BUTTON_Clearup, &CDlgBlueToothExc::OnBnClickedButtonClearup)
ON_BN_CLICKED(IDC_BUTTON_Test1, &CDlgBlueToothExc::OnBnClickedButtonTest1)
ON_EN_SETFOCUS(IDC_SENDTEXT, &CDlgBlueToothExc::OnEnSetfocusSendtext)
ON_BN_CLICKED(IDC_BUTTON_Receive, &CDlgBlueToothExc::OnBnClickedButtonReceive)
ON_BN_CLICKED(IDC_BUTTON_Finished, &CDlgBlueToothExc::OnBnClickedButtonFinished)
// ON_LBN_SELCHANGE(IDC_LIST_NearbyBthDev, &CDlgBlueToothExc::OnLbnSelchangeListNearbybthdev)
ON_BN_CLICKED(IDC_CHECK_ReceivedOnTimer, &CDlgBlueToothExc::OnBnClickedCheckReceivedontimer)
ON_WM_TIMER()
END_MESSAGE_MAP()
// CDlgBlueToothExc message handlers
BOOL CDlgBlueToothExc::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// 初始化控件
( (CButton*)GetDlgItem(IDC_CHECK_ShowRemembered) )->SetCheck ( TRUE );
CComboBox *pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_COM);
ASSERT ( pCombo );
for ( int i=0; i<32; i++ )
{
CString csCom;
csCom.Format ( L"COM%d", i+1 );
pCombo->AddString ( csCom );
}
pCombo->SetCurSel ( 1-1 ); // 默认在控件中显示的端口号
GetDlgItem(IDC_EDIT_Baud)->SetWindowText ( L"115200" );
EnableWindow_ConnCOM ( FALSE );
( (CButton*)GetDlgItem(IDC_CHECK_Hex) )->SetCheck ( TRUE );
// SetDlgItemText ( IDC_EDIT_ReceivedData_Hex, Data2HexString ( (char*)NOTE_Bluetooth, (int)wcslen(NOTE_Bluetooth) ) );
// GetDlgItem(IDC_EDIT_ReceivedData_Hex)->SendMessage ( WM_VSCROLL, (WPARAM)SB_BOTTOM, (LPARAM)NULL ); // 滚动在最底行
// SetDlgItemText ( IDC_EDIT_ReceivedData_String, NOTE_Bluetooth );
// GetDlgItem(IDC_EDIT_ReceivedData_String)->SendMessage ( WM_VSCROLL, (WPARAM)SB_BOTTOM, (LPARAM)NULL ); // 滚动在最底行
SetDlgItemText ( IDC_STATIC_ReceivedData_Hex_Length, _T("") );
SetDlgItemText ( IDC_STATIC_ReceivedData_String_Length, _T("") );
pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_Segment);
ASSERT ( pCombo );
pCombo->SetCurSel ( 0 );
pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_Section);
ASSERT ( pCombo );
pCombo->SetCurSel ( 0 );
// 初始化显示心电数据的框
CDlgDataShow *pDlgDataShow = CDlgDataShow::GetInstance ();
if ( pDlgDataShow )
{
CRect rcClient;
pDlgDataShow->GetWindowRect ( &rcClient );
CSize szArea = GetWorkAreaSize ();
CRect rcDataShow ( 0, 0, szArea.cx, rcClient.Height() );
pDlgDataShow->MoveWindow ( rcDataShow );
CRect rcMainWnd;
CenterWindow ();
GetWindowRect ( &rcMainWnd );
int nMainWndHeight = rcMainWnd.Height();
rcMainWnd.top = rcDataShow.bottom;
rcMainWnd.bottom = rcMainWnd.top + nMainWndHeight;
MoveWindow ( &rcMainWnd );
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CDlgBlueToothExc::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CDlgBlueToothExc::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDlgBlueToothExc::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CDlgBlueToothExc::OnBnClickedButtonScanbluetoothdevice()
{
// 先确定本地蓝牙设备,如果还没有就查找
t_LocalRadioInfo LocalRadioInfo;
if ( !GetCur_LocalRadioInfo ( LocalRadioInfo ) ) return;
// 搜索附近的蓝牙设备,并添加到列表中
CListBox *pListBox_NearbyBthDev = (CListBox*)GetDlgItem ( IDC_LIST_NearbyBthDev );
ASSERT ( pListBox_NearbyBthDev );
pListBox_NearbyBthDev->ResetContent ();
BOOL fReturnRemembered = ( (CButton*)GetDlgItem(IDC_CHECK_ShowRemembered) )->GetCheck ();
BOOL fIssueInquiry = ( (CButton*)GetDlgItem(IDC_CHECK_IssueInquiry) )->GetCheck ();
int nCount = 0;
if ( ( (CButton*)GetDlgItem(IDC_CHECK_Wizard) )->GetCheck () )
{
nCount = m_BlueTooth.ScanNearbyBthDev_Wizard ( GetSafeHwnd(), LocalRadioInfo.hRadio, _T("我现在正在搜索周边的蓝牙设备,您别打扰我! -- 谢红伟"),
FALSE, TRUE, fReturnRemembered, TRUE, TRUE, TRUE );
}
else
{
nCount = m_BlueTooth.ScanNearbyBthDev ( LocalRadioInfo.hRadio, TRUE, fReturnRemembered, TRUE, TRUE, fIssueInquiry );
}
if ( nCount <= 0 )
{
if ( nCount < 0 ) AfxMessageBox ( _T("Scan nearby bluetooth device failed") );
return;
}
for ( int i=0; i<nCount; i++ )
{
t_RemoteBthDevInfo &RemoteBthDevInfo = m_BlueTooth.m_Ary_RemoteBthDevInfo.GetAt(i);
CString csItemString;
csItemString.Format ( _T("%s ( %s )"), RemoteBthDevInfo.szName, m_BlueTooth.FormatBthAddress ( RemoteBt
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
利用蓝牙(Bluetooth) APIs 编写的多种方式进行蓝牙设备查找、服务发现启动,蓝牙虚拟串口的通信,支持16进制和字符串两种方式。<br> 你可以任意修改复制本代码,但请保留这段文字不要修改。<br> 希望我能为中国的软件行业尽一份薄力!
资源推荐
资源详情
资源评论
收起资源包目录
BlueToothExc_Plus.rar (25个子文件)
StaticDataCurve.h 1KB
BlueToothExc.suo 13KB
BlueToothExc.vcproj.CHRYS-T60.chrys.user 1KB
res
BlueToothExc.rc2 403B
BlueToothExc.ico 21KB
DlgBlueToothExc.cpp 20KB
BlueToothExc.h 579B
DlgBlueToothExc.h 2KB
PublicFunc.cpp 20KB
BlueToothExc.vcproj 6KB
stdafx.h 3KB
DlgDataShow.h 1KB
HwCOM.cpp 9KB
PublicFunc.h 4KB
Debug
BlueToothExc.exe 236KB
stdafx.cpp 212B
BlueTooth.h 4KB
StaticDataCurve.cpp 5KB
resource.h 3KB
BlueToothExc.sln 888B
HwCOM.h 2KB
BlueToothExc.cpp 2KB
BlueToothExc.rc 9KB
DlgDataShow.cpp 10KB
BlueTooth.cpp 13KB
共 25 条
- 1
chrys2000
- 粉丝: 70
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页