MFC_BLUETOOTH_TEST/MFC_BLUETOOTH_TEST/MFC_BLUETOOTH_TESTDlg.cpp
2021-05-02 03:47:57 +09:00

220 lines
5.2 KiB
C++

// MFC_BLUETOOTH_TESTDlg.cpp : 구현 파일
//
#include "stdafx.h"
#include "MFC_BLUETOOTH_TEST.h"
#include "MFC_BLUETOOTH_TESTDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMFC_BLUETOOTH_TESTDlg 대화 상자
CMFC_BLUETOOTH_TESTDlg::CMFC_BLUETOOTH_TESTDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(IDD_MFC_BLUETOOTH_TEST_DIALOG, pParent),
m_pCBluetoothRadioManager(NULL),
m_pCBluetoothDeviceManager(NULL)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMFC_BLUETOOTH_TESTDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CMFC_BLUETOOTH_TESTDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &CMFC_BLUETOOTH_TESTDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CMFC_BLUETOOTH_TESTDlg::OnBnClickedButton2)
ON_LBN_SELCHANGE(IDC_LIST1, &CMFC_BLUETOOTH_TESTDlg::OnLbnSelchangeList1)
ON_LBN_SELCHANGE(IDC_LIST2, &CMFC_BLUETOOTH_TESTDlg::OnLbnSelchangeList2)
ON_BN_CLICKED(IDC_BUTTON3, &CMFC_BLUETOOTH_TESTDlg::OnBnClickedButton3)
END_MESSAGE_MAP()
// CMFC_BLUETOOTH_TESTDlg 메시지 처리기
BOOL CMFC_BLUETOOTH_TESTDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 이 대화 상자의 아이콘을 설정합니다. 응용 프로그램의 주 창이 대화 상자가 아닐 경우에는
// 프레임워크가 이 작업을 자동으로 수행합니다.
SetIcon(m_hIcon, TRUE); // 큰 아이콘을 설정합니다.
SetIcon(m_hIcon, FALSE); // 작은 아이콘을 설정합니다.
// TODO: 여기에 추가 초기화 작업을 추가합니다.
return TRUE; // 포커스를 컨트롤에 설정하지 않으면 TRUE를 반환합니다.
}
// 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면
// 아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는
// 프레임워크에서 이 작업을 자동으로 수행합니다.
void CMFC_BLUETOOTH_TESTDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트입니다.
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다.
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 아이콘을 그립니다.
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
// 사용자가 최소화된 창을 끄는 동안에 커서가 표시되도록 시스템에서
// 이 함수를 호출합니다.
HCURSOR CMFC_BLUETOOTH_TESTDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CMFC_BLUETOOTH_TESTDlg::OnBnClickedButton1()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
m_pCBluetoothRadioManager = NULL;
m_pCBluetoothDeviceManager = NULL;
CListBox *pList = (CListBox*)GetDlgItem(IDC_LIST1);
if (!pList->GetSafeHwnd())
return;
while (pList->GetCount())
pList->DeleteString(0);
for (int i = 0; i < bm.GetRadioSize(); ++i)
{
CBluetoothRadioManager *pCBluetoothRadioManager = bm.GetRadio(i);
if (pCBluetoothRadioManager != NULL)
{
pList->InsertString(i, pCBluetoothRadioManager->GetName());
pList->SetItemDataPtr(i, pCBluetoothRadioManager);
}
}
}
void CMFC_BLUETOOTH_TESTDlg::OnBnClickedButton2()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
if (m_pCBluetoothDeviceManager == NULL)
return;
if (m_pCBluetoothDeviceManager->Connect())
{
//BYTE buf[4096] = { 0, };
CString strBuf;
static UINT dTryCnt = 0;
strBuf.Format(_T("kknd send : %d\r\n"), ++dTryCnt);
m_pCBluetoothDeviceManager->Send(CT2A(strBuf), strBuf.GetLength());
}
}
void CMFC_BLUETOOTH_TESTDlg::OnBnClickedButton3()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
if (m_pCBluetoothDeviceManager == NULL)
return;
m_pCBluetoothDeviceManager->Close();
}
void CMFC_BLUETOOTH_TESTDlg::OnLbnSelchangeList1()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
m_pCBluetoothRadioManager = NULL;
CListBox *pList = (CListBox*)GetDlgItem(IDC_LIST1);
if (!pList->GetSafeHwnd())
return;
int pos = pList->GetCurSel();
if (pos < 0)
return;
CBluetoothRadioManager *pCBluetoothRadioManager = reinterpret_cast<CBluetoothRadioManager*>(pList->GetItemDataPtr(pos));
if (pCBluetoothRadioManager == NULL)
return;
CListBox *pList2 = (CListBox*)GetDlgItem(IDC_LIST2);
if (!pList2->GetSafeHwnd())
return;
while (pList2->GetCount())
pList2->DeleteString(0);
UINT dIndex = 0;
for (int i = 0; i < pCBluetoothRadioManager->GetDeviceSize(); ++i)
{
CBluetoothDeviceManager *pCBluetoothDeviceManager = pCBluetoothRadioManager->GetDevice(i);
if (pCBluetoothDeviceManager != NULL)
{
pList2->InsertString(dIndex, pCBluetoothDeviceManager->GetName());
pList2->SetItemDataPtr(dIndex, pCBluetoothDeviceManager);
++dIndex;
}
}
m_pCBluetoothRadioManager = pCBluetoothRadioManager;
}
void CMFC_BLUETOOTH_TESTDlg::OnLbnSelchangeList2()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
m_pCBluetoothDeviceManager = NULL;
CListBox *pList = (CListBox*)GetDlgItem(IDC_LIST2);
if (!pList->GetSafeHwnd())
return;
int pos = pList->GetCurSel();
if (pos < 0)
return;
CBluetoothDeviceManager *pCBluetoothDeviceManager = reinterpret_cast<CBluetoothDeviceManager*>(pList->GetItemDataPtr(pos));
if (pCBluetoothDeviceManager == NULL)
return;
m_pCBluetoothDeviceManager = pCBluetoothDeviceManager;
}