RDSTerminalDlg.cpp
上传用户:hbzxgg2
上传日期:2009-03-28
资源大小:291k
文件大小:5k
源码类别:
Windows Mobile
开发平台:
Visual C++
- // RDSTerminalDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "RDSTerminal.h"
- #include "RDSTerminalDlg.h"
- #include "DlgSetting.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CRDSTerminalDlg dialog
- CRDSTerminalDlg::CRDSTerminalDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CRDSTerminalDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CRDSTerminalDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CRDSTerminalDlg, CDialog)
- #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
- ON_WM_SIZE()
- #endif
- //}}AFX_MSG_MAP
- // ON_BN_CLICKED(IDC_BUTTON1, &CRDSTerminalDlg::OnBnClickedButton1)
- ON_WM_PAINT()
- ON_COMMAND(ID_FILE_QUIT, &CRDSTerminalDlg::OnFileQuit)
- ON_COMMAND(ID_FILE_SHOWDATACARDIOGRAM, &CRDSTerminalDlg::OnFileShowdatacardiogram)
- ON_COMMAND(IDMENU_SETTING, &CRDSTerminalDlg::OnSetting)
- ON_COMMAND(ID_FILE_CONNECTBLUETOOTHDEVICE, &CRDSTerminalDlg::OnFileConnectbluetoothdevice)
- ON_COMMAND(ID_FILE_SENDTESTDATA, &CRDSTerminalDlg::OnFileSendtestdata)
- END_MESSAGE_MAP()
- // CRDSTerminalDlg message handlers
- BOOL CRDSTerminalDlg::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
- #ifdef WIN32_PLATFORM_WFSP
- if (!m_dlgCommandBar.Create(this) ||
- !m_dlgCommandBar.InsertMenuBar(IDR_MENU_MAIN))
- {
- TRACE0("Failed to create CommandBarn");
- return FALSE; // fail to create
- }
- #endif // WIN32_PLATFORM_WFSP
- // TODO: Add extra initialization here
- if ( m_pBlueTooth_WM && m_pBlueTooth_WM->Init ( g_CurDir ) )
- {
- }
- AfxMessageBox ( NOTE_BlueTooth_WM, MB_ICONINFORMATION );
- return TRUE; // return TRUE unless you set the focus to a control
- }
- #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
- void CRDSTerminalDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
- {
- DRA::RelayoutDialog(
- AfxGetInstanceHandle(),
- this->m_hWnd,
- DRA::GetDisplayMode() != DRA::Portrait ?
- MAKEINTRESOURCE(IDD_RDSTERMINAL_DIALOG_WIDE) :
- MAKEINTRESOURCE(IDD_RDSTERMINAL_DIALOG));
- }
- #endif
- void CRDSTerminalDlg::OnBnClickedButtonTest()
- {
- if ( m_pBlueTooth_WM && !m_pBlueTooth_WM->ScanNearbyBthDev (NULL,GetSafeHwnd()) )
- {
- AfxMessageBox ( L"Start scan nearby bluetooth device failed" );
- }
- }
- void CRDSTerminalDlg::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- CRect rcClient;
- GetClientRect ( &rcClient );
- if ( !m_bmpMainUI.GetSafeHandle() )
- {
- CString csBmpFileName;
- csBmpFileName.Format ( L"%simg\MainUI.bmp", g_CurDir );
- LoadBitmapFromFile ( m_bmpMainUI, csBmpFileName );
- }
- if ( m_bmpMainUI.GetSafeHandle() )
- {
- DrawBitmap ( m_bmpMainUI, &dc, rcClient, TRUE );
- }
- }
- void CRDSTerminalDlg::OnFileQuit()
- {
- OnCancel ();
- }
- void CRDSTerminalDlg::OnFileShowdatacardiogram()
- {
- }
- void CRDSTerminalDlg::OnSetting()
- {
- CDlgSetting DlgSetting;
- DlgSetting.DoModal ();
- }
- void CRDSTerminalDlg::OnFileConnectbluetoothdevice()
- {
- if ( strlen_s(g_Setting.RemoteBthDevInfo_InUsing.szName) < 1 )
- {
- AfxMessageBox ( FormatString(L"Please select bluetooth device") );
- PostMessage ( WM_COMMAND, IDMENU_SETTING );
- return;
- }
- SetWaitCursor ();
- int nError = m_pBlueTooth_WM->ConnectToBlueToothServer ( g_Setting.RemoteBthDevInfo_InUsing.RemoteAddr, g_Setting.szServiceInUsingGUID );
- ResotreCursor ();
- if ( nError == 0 )
- {
- AfxMessageBox ( FormatString(L"Connect to [%s] successfully", g_Setting.RemoteBthDevInfo_InUsing.szName), MB_ICONINFORMATION );
- return;
- }
- AfxMessageBox ( FormatString(L"Connect to [%s] failed. Error no : %d", g_Setting.RemoteBthDevInfo_InUsing.szName, nError) );
- }
- void CRDSTerminalDlg::OnFileSendtestdata()
- {
- if ( !m_pBlueTooth_WM->IsConnect() )
- {
- AfxMessageBox ( L"Not connect" );
- return;
- }
- SetWaitCursor ();
- // 挂机命令
- BYTE data[] = {0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x01,0xA7};
- if ( m_pBlueTooth_WM->Send ( data, LENGTH(data) ) != LENGTH(data) )
- {
- ResotreCursor ();
- AfxMessageBox ( L"Send data failed" );
- return;
- }
- Sleep ( 1000 );
- BYTE dataRecv[1024] = {0};
- int nRecvBytes = m_pBlueTooth_WM->Recv ( dataRecv, sizeof(dataRecv)-1 );
- if ( nRecvBytes > 0 )
- {
- dataRecv[nRecvBytes] = _T('0');
- CString csData = Data2HexString((char*)dataRecv, nRecvBytes );
- CString csString = GetCompatibleString((LPCTSTR)dataRecv,FALSE);
- ResotreCursor ();
- AfxMessageBox ( FormatString ( L"Recv string : rn%srnrnRecv Data : %s", csString, csData ) );
- }
- ResotreCursor ();
- }