www.gusucode.com > vc串口控制单片机实现AD转换和温度测量 > vc串口控制单片机实现AD转换和温度测量/csdn/myComm/CommSetDdlg.cpp

    // CommSetDdlg.cpp : implementation file
//

#include "stdafx.h"
#include "myComm.h"
#include "CommSetDdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCommSetDdlg dialog


CCommSetDdlg::CCommSetDdlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCommSetDdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCommSetDdlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CCommSetDdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCommSetDdlg)
	DDX_Control(pDX, IDC_COMBO_DATABITS, m_DataBits);
	DDX_Control(pDX, IDC_COMBO_PARITY, m_Parity);
	DDX_Control(pDX, IDC_COMBO_COMSELECT, m_Com);
	DDX_Control(pDX, IDC_COMBO_SPEED, m_Speed);
	DDX_Control(pDX, IDC_COMBO_STOPBITS, m_StopBits);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCommSetDdlg, CDialog)
	//{{AFX_MSG_MAP(CCommSetDdlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCommSetDdlg message handlers

BOOL CCommSetDdlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_Com.SetCurSel(0);
	m_DataBits.SetCurSel(0);
	m_Parity.SetCurSel(0);
	m_Speed.SetCurSel(1);
	m_StopBits.SetCurSel(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCommSetDdlg::OnOK() 
{
	// TODO: Add extra validation here
	CString strTemp;
	int index;

	//串口号
	m_nCom = m_Com.GetCurSel() + 1;

	//波特率
	index = m_Speed.GetCurSel();
	m_Speed.GetLBText(index, strTemp);
	m_nBaud = atoi(strTemp);
	m_strCommSet = strTemp;

	//校验位
	index = m_DataBits.GetCurSel();
	switch(index)
	{
	case 0:
		m_cParity='N';
		break;
	case 1:
		m_cParity='O';
		break;
	case 2:
		m_cParity='E';
		break;
	}
	m_strCommSet = m_strCommSet + "," + m_cParity;
	//数据位
	index = m_DataBits.GetCurSel();
	m_DataBits.GetLBText(index, strTemp);
	m_nDatabits = atoi(strTemp);
	m_strCommSet = m_strCommSet + "," + strTemp;

	//停止位
	index = m_StopBits.GetCurSel();
	m_StopBits.GetLBText(index, strTemp);
	m_nStopbits = m_StopBits.GetCurSel() + 1;
	m_strCommSet = m_strCommSet + "," + strTemp;

	CDialog::OnOK();
}