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

Windows Mobile

开发平台:

Visual C++

  1. // DlgSetting.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "RDSTerminal.h"
  5. #include "DlgSetting.h"
  6. #include <tpcshell.h> // for SHSendBackToFocusWindow()
  7. #include "InitSys.h"
  8. // CDlgSetting 对话框
  9. IMPLEMENT_DYNAMIC(CDlgSetting, CDialog)
  10. CDlgSetting::CDlgSetting(CWnd* pParent /*=NULL*/)
  11. : CDialog(CDlgSetting::IDD, pParent)
  12. {
  13. SetWaitCursor ();
  14. }
  15. CDlgSetting::~CDlgSetting()
  16. {
  17. }
  18. void CDlgSetting::DoDataExchange(CDataExchange* pDX)
  19. {
  20. CDialog::DoDataExchange(pDX);
  21. }
  22. BEGIN_MESSAGE_MAP(CDlgSetting, CDialog)
  23. ON_BN_CLICKED(IDC_BUTTON_Scan, &CDlgSetting::OnBnClickedButtonScan)
  24. ON_WM_TIMER()
  25. ON_MESSAGE(WM_SCAN_BLUETOOTH_DEVICE_FINISHED,OnWM_SCAN_BLUETOOTH_DEVICE_FINISHED)
  26. ON_BN_CLICKED(IDC_BUTTON_Restore, &CDlgSetting::OnBnClickedButtonRestore)
  27. END_MESSAGE_MAP()
  28. // CDlgSetting 消息处理程序
  29. BOOL CDlgSetting::OnInitDialog()
  30. {
  31. CDialog::OnInitDialog();
  32. #ifdef WIN32_PLATFORM_WFSP
  33. if (!m_dlgCommandBar.Create(this) ||
  34.     !m_dlgCommandBar.InsertMenuBar(IDR_MENU_Setting))
  35. {
  36. TRACE0("Failed to create CommandBarn");
  37. return FALSE;      // fail to create
  38. }
  39. #endif // WIN32_PLATFORM_WFSP
  40. SetTimer ( TIMERID_INITED, 10, NULL );
  41. return TRUE;  // return TRUE unless you set the focus to a control
  42. // 异常: OCX 属性页应返回 FALSE
  43. }
  44. void CDlgSetting::OnBnClickedButtonScan()
  45. {
  46. ASSERT ( m_pBlueTooth_WM );
  47. if ( !m_pBlueTooth_WM->ScanNearbyBthDev ( NULL, GetSafeHwnd() ) )
  48. {
  49. AfxMessageBox ( L"Start scan nearby bluetooth device taske failed" );
  50. }
  51. SetDlgItemText ( IDC_STATIC_Status, L"Scaning ..." );
  52. }
  53. void CDlgSetting::OnTimer(UINT_PTR nIDEvent)
  54. {
  55. switch ( nIDEvent )
  56. {
  57. case TIMERID_INITED:
  58. {
  59. SetCtrlValue ();
  60. ResotreCursor ();
  61. KillTimer ( TIMERID_INITED );
  62. break;
  63. }
  64. }
  65. CDialog::OnTimer(nIDEvent);
  66. }
  67. void CDlgSetting::SetCtrlValue(void)
  68. {
  69. AddRemoteBthDevInfoToCombo ();
  70. SetDlgItemText ( IDC_STATIC_Status, L"Select bluetooth device" );
  71. SetDlgItemText ( IDC_EDIT_ServiceGUID, g_Setting.szServiceInUsingGUID );
  72. }
  73. BOOL CDlgSetting::GetCtrlValue(void)
  74. {
  75. CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_NearbyBthDev);
  76. ASSERT ( pComboBox );
  77. ASSERT ( m_pBlueTooth_WM );
  78. int nSelIndex = pComboBox->GetCurSel ();
  79. if ( nSelIndex >= 0 && nSelIndex < pComboBox->GetCount () && nSelIndex < m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetSize() )
  80. {
  81. t_RemoteBthDevInfo &RemoteBthDevInfo = m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetAt(nSelIndex);
  82. memcpy ( &g_Setting.RemoteBthDevInfo_InUsing, &RemoteBthDevInfo, sizeof(t_RemoteBthDevInfo) );
  83. }
  84. GetDlgItemText ( IDC_EDIT_ServiceGUID, g_Setting.szServiceInUsingGUID, LENGTH(g_Setting.szServiceInUsingGUID) );
  85. return TRUE;
  86. }
  87. void CDlgSetting::OnOK(void)
  88. {
  89. if ( !GetCtrlValue() ) return;
  90. CDialog::OnOK ();
  91. }
  92. LRESULT CDlgSetting::OnWM_SCAN_BLUETOOTH_DEVICE_FINISHED ( WPARAM wParam, LPARAM lParam )
  93. {
  94. int nRetValue = (int)wParam;
  95. if ( nRetValue < 0 ) return FALSE;
  96. AddRemoteBthDevInfoToCombo ();
  97. CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_NearbyBthDev);
  98. ASSERT ( pComboBox );
  99. pComboBox->ShowDropDown ( TRUE );
  100. pComboBox->SetFocus ();
  101. SetDlgItemText ( IDC_STATIC_Status, L"Select bluetooth device" );
  102. return TRUE;
  103. }
  104. void CDlgSetting::AddRemoteBthDevInfoToCombo(void)
  105. {
  106. CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_NearbyBthDev);
  107. ASSERT ( pComboBox );
  108. ASSERT ( m_pBlueTooth_WM );
  109. pComboBox->ResetContent ();
  110. for ( int i=0; i<m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetSize(); i++ )
  111. {
  112. t_RemoteBthDevInfo &RemoteBthDevInfo = m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetAt(i);
  113. pComboBox->AddString ( RemoteBthDevInfo.szName );
  114. }
  115. int nFoundIndex = m_pBlueTooth_WM->Find_RemoteBthDevInfo ( g_Setting.RemoteBthDevInfo_InUsing.RemoteAddr );
  116. if ( nFoundIndex >= 0 ) pComboBox->SetCurSel ( nFoundIndex );
  117. }
  118. BOOL CDlgSetting::PreTranslateMessage(MSG* pMsg) 
  119. {
  120. // 以下代码是让编辑框能响应 BACK 按键,删除输入的字符
  121. if ( pMsg->message == WM_HOTKEY )
  122. {
  123. if ( HIWORD(pMsg->lParam) == VK_TBACK   )   
  124. {   
  125. SHSendBackToFocusWindow ( WM_HOTKEY, pMsg->wParam, pMsg->lParam );   
  126. return   TRUE;   
  127. }
  128. }
  129. return CDialog::PreTranslateMessage(pMsg);
  130. }
  131. void CDlgSetting::OnBnClickedButtonRestore()
  132. {
  133. SetDefaultSetting ();
  134. SetCtrlValue ();
  135. }