📄 btpairingdlg.cpp
字号:
/*
Filename : BTPairingDlg.cpp
Part of : Phone Navigator
Description : Implementation of bluetooth pairing dialog of PhoneNavigator
Version : 3.2
This example is only to be used with PC Connectivity API version 3.2.
Compability ("as is") with future versions is not quaranteed.
Copyright (c) 2007 Nokia Corporation.
This material, including but not limited to documentation and any related
computer programs, is protected by intellectual property rights of Nokia
Corporation and/or its licensors.
All rights are reserved. Reproducing, modifying, translating, or
distributing any or all of this material requires the prior written consent
of Nokia Corporation. Nokia Corporation retains the right to make changes
to this material at any time without notice. A copyright license is hereby
granted to download and print a copy of this material for personal use only.
No other license to any other intellectual property rights is granted. The
material is provided "as is" without warranty of any kind, either express or
implied, including without limitation, any warranty of non-infringement,
merchantability and fitness for a particular purpose. In no event shall
Nokia Corporation be liable for any direct, indirect, special, incidental,
or consequential loss or damages, including but not limited to, lost profits
or revenue,loss of use, cost of substitute program, or loss of data or
equipment arising out of the use or inability to use the material, even if
Nokia Corporation has been advised of the likelihood of such damages occurring.
*/
#include "stdafx.h"
#include "phonenavigator.h"
#include "BTPairingDlg.h"
#include "BTPasswordDlg.h"
#include "BTProgressDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBTPairingDlg dialog
BOOL g_bSearchCancelled = FALSE;
CBTProgressDlg g_ProgressDlg;
//===================================================================
// ProcessMessages
//
// Message loop. This is called frequently during the device search,
// to get window messages processed during this time consuming task.
//===================================================================
void ProcessMessages()
{
MSG msg;
while( ::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage( &msg);
::DispatchMessage( &msg);
}
}
//===================================================================
// BTPairingNotifyCallback
//
// BT device searching callback function. If the progress dialog is
// visible, sets the progress dialog progress bar to the correct
// position.
// If global variable g_bSearchCancelled is set to TRUE, this
// function returns ECONA_CANCELLED, and connectivity API stops
// the device search.
// In other situations this function must always return CONA_OK.
//===================================================================
static DWORD CALLBACK BTPairingNotifyCallback( DWORD dwState, CONAPI_CONNECTION_INFO *pInfo)
{
DWORD dwRet = CONA_OK;
// check that progress dialog exists
if( ::IsWindow( g_ProgressDlg.m_hWnd))
{
g_ProgressDlg.SetProgress( dwState);
}
if( g_bSearchCancelled)
{
// If user has clicked Cancel, return ECONA_CANCELLED
dwRet = ECONA_CANCELLED;
}
ProcessMessages();
return dwRet;
}
//===================================================================
// CBTPairingDlg
//===================================================================
// Constructor
//
//===================================================================
CBTPairingDlg::CBTPairingDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBTPairingDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBTPairingDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hDM = NULL;
DWORD dwRet = CONAOpenDM( &m_hDM);
if( dwRet != CONA_OK)
{
m_hDM = NULL;
ErrorMessageDlg( L"CONAOpenDM failed.", dwRet);
}
}
//===================================================================
// Destructor
//
//===================================================================
CBTPairingDlg::~CBTPairingDlg()
{
DWORD dwRet = ECONA_UNKNOWN_ERROR;
if( m_hDM)
{
dwRet = CONACloseDM( m_hDM);
if( dwRet != CONA_OK)
{
ErrorMessageDlg( L"CONACloseDM failed.", dwRet);
}
}
}
void CBTPairingDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBTPairingDlg)
DDX_Control(pDX, IDC_LIST_BT_PHONES, m_PhoneList);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_CHECK_CACHE, m_CheckUseCache);
DDX_Control(pDX, IDC_COMBO_OPTIONS, m_ComboSearchOptions);
}
BEGIN_MESSAGE_MAP(CBTPairingDlg, CDialog)
//{{AFX_MSG_MAP(CBTPairingDlg)
ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
ON_BN_CLICKED(IDC_BUTTON_PAIR, OnButtonPair)
ON_BN_CLICKED(IDC_BUTTON_UNPAIR, OnButtonUnpair)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_SET_TRUSTED, OnButtonSetTrusted)
ON_BN_CLICKED(IDC_BUTTON_SET_UNTRUSTED, OnButtonSetUntrusted)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBTPairingDlg message handlers
//===================================================================
// OnInitDialog
//
//===================================================================
BOOL CBTPairingDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rcList(0,0,0,0);
m_PhoneList.GetClientRect(rcList);
m_PhoneList.InsertColumn(0, _T("Phone name"), LVCFMT_LEFT, rcList.Width()/2);
m_PhoneList.InsertColumn(1, _T("Status"), LVCFMT_LEFT, rcList.Width()/2);
m_PhoneList.SetExtendedStyle( m_PhoneList.GetExtendedStyle() | LVS_EX_FULLROWSELECT);
m_ComboSearchOptions.SetCurSel(0);
RefreshPhoneList();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//===================================================================
// ClearPhoneList
//
// Removes all items from the phone list, and frees memory
// allocated for each list item data
//===================================================================
void CBTPairingDlg::ClearPhoneList()
{
int i = 0;
int iCount = m_PhoneList.GetItemCount();
CBTDevice *pDevice = NULL;
for( i=0; i<iCount; i++)
{
pDevice = (CBTDevice*)m_PhoneList.GetItemData( i);
if( pDevice)
{
delete pDevice;
pDevice = NULL;
}
}
m_PhoneList.DeleteAllItems();
}
//===================================================================
// GetSelectedDevice
//
// Returns pointer to the item data of the currently selected item
// in the phone list control, or NULL if no item is selected
//===================================================================
CBTDevice * CBTPairingDlg::GetSelectedDevice()
{
int i = 0;
int iCount = m_PhoneList.GetItemCount();
CBTDevice *pDevice = NULL;
for( i=0; i<iCount; i++)
{
if( m_PhoneList.GetItemState( i, LVIS_SELECTED) & LVIS_SELECTED)
{
pDevice = (CBTDevice*)m_PhoneList.GetItemData( i);
break;
}
}
return pDevice;
}
//===================================================================
// RefreshPhoneList
//
// Refreshes the phone list to the list control. If bSearchDevices
// is TRUE, searches all BT devices using connectivity API, else
// only copies the device information from memory to the list control.
//===================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -