RDSTerminalDlg.cpp
上传用户:hbzxgg2
上传日期:2009-03-28
资源大小:291k
文件大小:5k
源码类别:

Windows Mobile

开发平台:

Visual C++

  1. // RDSTerminalDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "RDSTerminal.h"
  5. #include "RDSTerminalDlg.h"
  6. #include "DlgSetting.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. // CRDSTerminalDlg dialog
  11. CRDSTerminalDlg::CRDSTerminalDlg(CWnd* pParent /*=NULL*/)
  12. : CDialog(CRDSTerminalDlg::IDD, pParent)
  13. {
  14. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  15. }
  16. void CRDSTerminalDlg::DoDataExchange(CDataExchange* pDX)
  17. {
  18. CDialog::DoDataExchange(pDX);
  19. }
  20. BEGIN_MESSAGE_MAP(CRDSTerminalDlg, CDialog)
  21. #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
  22. ON_WM_SIZE()
  23. #endif
  24. //}}AFX_MSG_MAP
  25. // ON_BN_CLICKED(IDC_BUTTON1, &CRDSTerminalDlg::OnBnClickedButton1)
  26. ON_WM_PAINT()
  27. ON_COMMAND(ID_FILE_QUIT, &CRDSTerminalDlg::OnFileQuit)
  28. ON_COMMAND(ID_FILE_SHOWDATACARDIOGRAM, &CRDSTerminalDlg::OnFileShowdatacardiogram)
  29. ON_COMMAND(IDMENU_SETTING, &CRDSTerminalDlg::OnSetting)
  30. ON_COMMAND(ID_FILE_CONNECTBLUETOOTHDEVICE, &CRDSTerminalDlg::OnFileConnectbluetoothdevice)
  31. ON_COMMAND(ID_FILE_SENDTESTDATA, &CRDSTerminalDlg::OnFileSendtestdata)
  32. END_MESSAGE_MAP()
  33. // CRDSTerminalDlg message handlers
  34. BOOL CRDSTerminalDlg::OnInitDialog()
  35. {
  36. CDialog::OnInitDialog();
  37. // Set the icon for this dialog.  The framework does this automatically
  38. //  when the application's main window is not a dialog
  39. SetIcon(m_hIcon, TRUE); // Set big icon
  40. SetIcon(m_hIcon, FALSE); // Set small icon
  41. #ifdef WIN32_PLATFORM_WFSP
  42. if (!m_dlgCommandBar.Create(this) ||
  43.     !m_dlgCommandBar.InsertMenuBar(IDR_MENU_MAIN))
  44. {
  45. TRACE0("Failed to create CommandBarn");
  46. return FALSE;      // fail to create
  47. }
  48. #endif // WIN32_PLATFORM_WFSP
  49. // TODO: Add extra initialization here
  50. if ( m_pBlueTooth_WM && m_pBlueTooth_WM->Init ( g_CurDir ) )
  51. {
  52. }
  53. AfxMessageBox ( NOTE_BlueTooth_WM, MB_ICONINFORMATION );
  54. return TRUE;  // return TRUE  unless you set the focus to a control
  55. }
  56. #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
  57. void CRDSTerminalDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
  58. {
  59. DRA::RelayoutDialog(
  60. AfxGetInstanceHandle(), 
  61. this->m_hWnd, 
  62. DRA::GetDisplayMode() != DRA::Portrait ? 
  63. MAKEINTRESOURCE(IDD_RDSTERMINAL_DIALOG_WIDE) : 
  64. MAKEINTRESOURCE(IDD_RDSTERMINAL_DIALOG));
  65. }
  66. #endif
  67. void CRDSTerminalDlg::OnBnClickedButtonTest()
  68. {
  69. if ( m_pBlueTooth_WM && !m_pBlueTooth_WM->ScanNearbyBthDev (NULL,GetSafeHwnd()) )
  70. {
  71. AfxMessageBox ( L"Start scan nearby bluetooth device failed" );
  72. }
  73. }
  74. void CRDSTerminalDlg::OnPaint()
  75. {
  76. CPaintDC dc(this); // device context for painting
  77. CRect rcClient;
  78. GetClientRect ( &rcClient );
  79. if ( !m_bmpMainUI.GetSafeHandle() )
  80. {
  81. CString csBmpFileName;
  82. csBmpFileName.Format ( L"%simg\MainUI.bmp", g_CurDir );
  83. LoadBitmapFromFile ( m_bmpMainUI, csBmpFileName );
  84. }
  85. if ( m_bmpMainUI.GetSafeHandle() )
  86. {
  87. DrawBitmap ( m_bmpMainUI, &dc, rcClient, TRUE );
  88. }
  89. }
  90. void CRDSTerminalDlg::OnFileQuit()
  91. {
  92. OnCancel ();
  93. }
  94. void CRDSTerminalDlg::OnFileShowdatacardiogram()
  95. {
  96. }
  97. void CRDSTerminalDlg::OnSetting()
  98. {
  99. CDlgSetting DlgSetting;
  100. DlgSetting.DoModal ();
  101. }
  102. void CRDSTerminalDlg::OnFileConnectbluetoothdevice()
  103. {
  104. if ( strlen_s(g_Setting.RemoteBthDevInfo_InUsing.szName) < 1 )
  105. {
  106. AfxMessageBox ( FormatString(L"Please select bluetooth device") );
  107. PostMessage ( WM_COMMAND, IDMENU_SETTING );
  108. return;
  109. }
  110. SetWaitCursor ();
  111. int nError = m_pBlueTooth_WM->ConnectToBlueToothServer ( g_Setting.RemoteBthDevInfo_InUsing.RemoteAddr, g_Setting.szServiceInUsingGUID );
  112. ResotreCursor ();
  113. if ( nError == 0 )
  114. {
  115. AfxMessageBox ( FormatString(L"Connect to [%s] successfully", g_Setting.RemoteBthDevInfo_InUsing.szName), MB_ICONINFORMATION );
  116. return;
  117. }
  118. AfxMessageBox ( FormatString(L"Connect to [%s] failed. Error no : %d", g_Setting.RemoteBthDevInfo_InUsing.szName, nError) );
  119. }
  120. void CRDSTerminalDlg::OnFileSendtestdata()
  121. {
  122. if ( !m_pBlueTooth_WM->IsConnect() )
  123. {
  124. AfxMessageBox ( L"Not connect" );
  125. return;
  126. }
  127. SetWaitCursor ();
  128. // 挂机命令
  129. BYTE data[] = {0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x01,0xA7};
  130. if ( m_pBlueTooth_WM->Send ( data, LENGTH(data) ) != LENGTH(data) )
  131. {
  132. ResotreCursor ();
  133. AfxMessageBox ( L"Send data failed" );
  134. return;
  135. }
  136. Sleep ( 1000 );
  137. BYTE dataRecv[1024] = {0};
  138. int nRecvBytes = m_pBlueTooth_WM->Recv ( dataRecv, sizeof(dataRecv)-1 );
  139. if ( nRecvBytes > 0 )
  140. {
  141. dataRecv[nRecvBytes] = _T('0');
  142. CString csData = Data2HexString((char*)dataRecv, nRecvBytes );
  143. CString csString = GetCompatibleString((LPCTSTR)dataRecv,FALSE);
  144. ResotreCursor ();
  145. AfxMessageBox ( FormatString ( L"Recv string : rn%srnrnRecv Data : %s", csString, csData ) );
  146. }
  147. ResotreCursor ();
  148. }