⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgsetting.cpp

📁 ◆◆◆ 《如何在 Windows Mobile (WinCE 5.0) 中用Vc++编程查找并连接周围的蓝牙(Bluetooth)设备》◆◆◆ 如何在手机中编程实现蓝牙通信即是本文将要阐述的内容
💻 CPP
字号:
// DlgSetting.cpp : 实现文件
//

#include "stdafx.h"
#include "RDSTerminal.h"
#include "DlgSetting.h"
#include <tpcshell.h>	// for SHSendBackToFocusWindow()
#include "InitSys.h"


// CDlgSetting 对话框

IMPLEMENT_DYNAMIC(CDlgSetting, CDialog)

CDlgSetting::CDlgSetting(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSetting::IDD, pParent)
{
	SetWaitCursor ();
}

CDlgSetting::~CDlgSetting()
{
}

void CDlgSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDlgSetting, CDialog)
	ON_BN_CLICKED(IDC_BUTTON_Scan, &CDlgSetting::OnBnClickedButtonScan)
	ON_WM_TIMER()
	ON_MESSAGE(WM_SCAN_BLUETOOTH_DEVICE_FINISHED,OnWM_SCAN_BLUETOOTH_DEVICE_FINISHED)
	ON_BN_CLICKED(IDC_BUTTON_Restore, &CDlgSetting::OnBnClickedButtonRestore)
END_MESSAGE_MAP()


// CDlgSetting 消息处理程序

BOOL CDlgSetting::OnInitDialog()
{
	CDialog::OnInitDialog();

#ifdef WIN32_PLATFORM_WFSP
	if (!m_dlgCommandBar.Create(this) ||
	    !m_dlgCommandBar.InsertMenuBar(IDR_MENU_Setting))
	{
		TRACE0("Failed to create CommandBar\n");
		return FALSE;      // fail to create
	}
#endif // WIN32_PLATFORM_WFSP

	SetTimer ( TIMERID_INITED, 10, NULL );

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CDlgSetting::OnBnClickedButtonScan()
{
	ASSERT ( m_pBlueTooth_WM );
	if ( !m_pBlueTooth_WM->ScanNearbyBthDev ( NULL, GetSafeHwnd() ) )
	{
		AfxMessageBox ( L"Start scan nearby bluetooth device taske failed" );
	}
	SetDlgItemText ( IDC_STATIC_Status, L"Scaning ..." );
}

void CDlgSetting::OnTimer(UINT_PTR nIDEvent)
{
	switch ( nIDEvent )
	{
	case TIMERID_INITED:
		{
			SetCtrlValue ();
			ResotreCursor ();
			KillTimer ( TIMERID_INITED );
			break;
		}
	}

	CDialog::OnTimer(nIDEvent);
}

void CDlgSetting::SetCtrlValue(void)
{
	AddRemoteBthDevInfoToCombo ();

	SetDlgItemText ( IDC_STATIC_Status, L"Select bluetooth device" );

	SetDlgItemText ( IDC_EDIT_ServiceGUID, g_Setting.szServiceInUsingGUID );
}

BOOL CDlgSetting::GetCtrlValue(void)
{
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_NearbyBthDev);
	ASSERT ( pComboBox );
	ASSERT ( m_pBlueTooth_WM );
	int nSelIndex = pComboBox->GetCurSel ();
	if ( nSelIndex >= 0 && nSelIndex < pComboBox->GetCount () && nSelIndex < m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetSize() )
	{
		t_RemoteBthDevInfo &RemoteBthDevInfo = m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetAt(nSelIndex);
		memcpy ( &g_Setting.RemoteBthDevInfo_InUsing, &RemoteBthDevInfo, sizeof(t_RemoteBthDevInfo) );
	}

	GetDlgItemText ( IDC_EDIT_ServiceGUID, g_Setting.szServiceInUsingGUID, LENGTH(g_Setting.szServiceInUsingGUID) );

	return TRUE;
}

void CDlgSetting::OnOK(void)
{
	if ( !GetCtrlValue() ) return;
	CDialog::OnOK ();
}

LRESULT CDlgSetting::OnWM_SCAN_BLUETOOTH_DEVICE_FINISHED ( WPARAM wParam, LPARAM lParam )
{
	int nRetValue = (int)wParam;
	if ( nRetValue < 0 ) return FALSE;
	AddRemoteBthDevInfoToCombo ();
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_NearbyBthDev);
	ASSERT ( pComboBox );
	pComboBox->ShowDropDown ( TRUE );
	pComboBox->SetFocus ();
	SetDlgItemText ( IDC_STATIC_Status, L"Select bluetooth device" );
	return TRUE;
}

void CDlgSetting::AddRemoteBthDevInfoToCombo(void)
{
	CComboBox *pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_NearbyBthDev);
	ASSERT ( pComboBox );
	ASSERT ( m_pBlueTooth_WM );
	pComboBox->ResetContent ();

	for ( int i=0; i<m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetSize(); i++ )
	{
		t_RemoteBthDevInfo &RemoteBthDevInfo = m_pBlueTooth_WM->m_Ary_RemoteBthDevInfo.GetAt(i);
		pComboBox->AddString ( RemoteBthDevInfo.szName );
	}
	int nFoundIndex = m_pBlueTooth_WM->Find_RemoteBthDevInfo ( g_Setting.RemoteBthDevInfo_InUsing.RemoteAddr );
	if ( nFoundIndex >= 0 ) pComboBox->SetCurSel ( nFoundIndex );
}

BOOL CDlgSetting::PreTranslateMessage(MSG* pMsg) 
{
	// 以下代码是让编辑框能响应 BACK 按键,删除输入的字符
	if ( pMsg->message == WM_HOTKEY )
	{
		if ( HIWORD(pMsg->lParam) == VK_TBACK   )   
		{   
			SHSendBackToFocusWindow ( WM_HOTKEY, pMsg->wParam, pMsg->lParam );   
			return   TRUE;   
		}
	}

	return CDialog::PreTranslateMessage(pMsg);
}

void CDlgSetting::OnBnClickedButtonRestore()
{
	SetDefaultSetting ();
	SetCtrlValue ();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -