www.pudn.com > bluetoothtest.rar > BTtestDlg.cpp


// BTtestDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "BTtest.h" 
#include "BTtestDlg.h" 
#include "BlueTooth.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CBTtestDlg dialog 
 
CBTtestDlg::CBTtestDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CBTtestDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CBTtestDlg) 
	m_rece = _T(""); 
	m_send = _T(""); 
	m_portid = _T(""); 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CBTtestDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CBTtestDlg) 
	DDX_Text(pDX, IDC_EDIT_RECE, m_rece); 
	DDX_Text(pDX, IDC_EDIT_SEND, m_send); 
	DDX_CBString(pDX, IDC_COMBO2, m_portid); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CBTtestDlg, CDialog) 
	//{{AFX_MSG_MAP(CBTtestDlg) 
	ON_BN_CLICKED(IDC_BUTTON3, OnExit) 
	ON_BN_CLICKED(IDC_BUTTON1, OnOpen) 
	ON_BN_CLICKED(IDC_BUTTON2, OnSend) 
	ON_BN_CLICKED(IDC_BUTTON4, OnRecieve) 
	ON_BN_CLICKED(IDC_BUTTON6, OnClose) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CBTtestDlg message handlers 
 
BOOL CBTtestDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	CenterWindow(GetDesktopWindow());	// center to the hpc screen 
 
	// TODO: Add extra initialization here 
	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
 
 
void CBTtestDlg::OnExit()  
{ 
	CDialog::OnCancel();	 
} 
 
void CBTtestDlg::OnOpen()  
{ 
       BlueTooth bth; 
	   bth.OnInitDialog(); 
	   GetDlgItemText(IDC_COMBO2,m_portid); 
	    
	   if(bth.OpenPort(m_portid)) 
		   AfxMessageBox(CString("opened!")); 
	    
} 
 
void CBTtestDlg::OnSend()  
{ 
 
	BlueTooth bth; 
	UpdateData(TRUE); 
	bth.OnSend(m_send); 
	UpdateData(FALSE); 
} 
 
void CBTtestDlg::OnRecieve()  
{ 
 
	UpdateData(); 
	BlueTooth bth; 
	bth.OnRece(); 
//	MessageBox(CString(bth.str_receive)); 
	m_rece=bth.str_receive; 
	SetDlgItemText(IDC_EDIT_RECE,m_rece); 
	UpdateData(FALSE); 
 
} 
 
void CBTtestDlg::OnClose()  
{ 
 
	BlueTooth bth; 
	bth.ClosePort(); 
}