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

📄 setupdlg.cpp

📁 一个GPS串口通讯的程序
💻 CPP
字号:
// SetupDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPS_Comm.h"
#include "SetupDlg.h"

//#include "SerialPort.h" //包含串口类

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

/////////////////////////////////////////////////////////////////////////////
// CSetupDlg dialog


CSetupDlg::CSetupDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSetupDlg::IDD, pParent)
{

	//{{AFX_DATA_INIT(CSetupDlg)
	m_strBaudRate = _T("");
	m_strComm = _T("");
	m_strDataBits = _T("");
	m_strParity = _T("");
	m_strStopBits = _T("");
	//}}AFX_DATA_INIT
}


//构造对话框时 传入串口设备块
CSetupDlg::CSetupDlg(CWnd* pParent, DCB dcb)
	: CDialog(CSetupDlg::IDD, pParent)
{
     m_dcb=dcb;  
}


//构造对话框时,传入串口类实例,以取得串口设备块及串口号
CSetupDlg::CSetupDlg(CWnd* pParent, CSerialPortEx* pPortEx)
	: CDialog(CSetupDlg::IDD, pParent)
{
	m_dcb=pPortEx->GetDCB();
	char temp[10];
	m_strComm = _T(CString("COM")+itoa(pPortEx->m_nPortNr,temp,10));
}




void CSetupDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetupDlg)
	DDX_CBString(pDX, IDC_BAUDRATECOMBO, m_strBaudRate);
	DDX_CBString(pDX, IDC_COMMCOMBO, m_strComm);
	DDX_CBString(pDX, IDC_DATABITSCOMBO, m_strDataBits);
	DDX_CBString(pDX, IDC_PARITYCOMBO, m_strParity);
	DDX_CBString(pDX, IDC_STOPBITSCOMBO, m_strStopBits);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CSetupDlg message handlers


//对话框初始化时,用先前的值填充各框
BOOL CSetupDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	CString strTemp;
	strTemp.Format("%d",m_dcb.BaudRate );
	((CComboBox*)GetDlgItem(IDC_BAUDRATECOMBO))->SelectString(0,strTemp);

	((CComboBox*)GetDlgItem(IDC_PARITYCOMBO))->SetCurSel(m_dcb.Parity);

	((CComboBox*)GetDlgItem(IDC_STOPBITSCOMBO))->SetCurSel(m_dcb.StopBits);

	strTemp.Format("%d",m_dcb.ByteSize); //数据位
	((CComboBox*)GetDlgItem(IDC_DATABITSCOMBO))->SelectString(0,strTemp);


	CComboBox* pcommChoice=(CComboBox*)this->GetDlgItem(IDC_COMMCOMBO);
	switch(m_strComm[3]) //串口号的第四个字母
	{
	case '1':
		pcommChoice->SetCurSel(0);
		break;
	case '2':
		pcommChoice->SetCurSel(1);
		break;
	case '3':
		pcommChoice->SetCurSel(2);
		break;
	case '4':
		pcommChoice->SetCurSel(3);
		break;
	default:
		break;
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetupDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

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