📄 compropertydlg.cpp
字号:
// ComPropertyDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "ComPropertyDlg.h"
// CComPropertyDlg 对话框
IMPLEMENT_DYNAMIC(CComPropertyDlg, CDialog)
CComPropertyDlg::CComPropertyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CComPropertyDlg::IDD, pParent)
{
this->m_pDcb = NULL;
this->m_pPortNum = NULL;
}
CComPropertyDlg::~CComPropertyDlg()
{
}
void CComPropertyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CComPropertyDlg, CDialog)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()
// CComPropertyDlg 消息处理程序
BOOL CComPropertyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
//串口号
CComboBox*pComb=NULL;
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO1);
pComb->AddString("Com1");
pComb->AddString("Com2");
pComb->AddString("Com3");
CString c;
c.Format("Com%d",*this->m_pPortNum);
int nIndex=pComb->FindString(0,c);
pComb->SetCurSel(nIndex);
//波特率
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO2);
pComb->AddString("1200");
pComb->AddString("2400");
pComb->AddString("4800");
pComb->AddString("9600");
c.Format("%d",this->m_pDcb->BaudRate);
nIndex=pComb->FindString(0,c);
pComb->SetCurSel(nIndex);
//数据位
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO3);
pComb->AddString("4");
pComb->AddString("5");
pComb->AddString("6");
pComb->AddString("7");
pComb->AddString("8");
c.Format("%d",this->m_pDcb->ByteSize);
nIndex=pComb->FindString(0,c);
pComb->SetCurSel(nIndex);
//停止位
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO4);
pComb->AddString("1");
pComb->AddString("1.5");
pComb->AddString("2");
nIndex=this->m_pDcb->StopBits;
pComb->SetCurSel(nIndex);
//校验
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO5);
pComb->AddString("无校验");
pComb->AddString("奇校验");
pComb->AddString("偶校验");
nIndex=this->m_pDcb->Parity;
pComb->SetCurSel(nIndex);
this->m_BtnOk.SubclassDlgItem(IDOK,this);
this->m_BtnOk.SetIcon(IDI_OK);
this->m_BtnOk.SetFlat(false);
this->m_BtnCancel.SubclassDlgItem(IDCANCEL,this);
this->m_BtnCancel.SetIcon(IDI_CANCEL);
this->m_BtnCancel.SetFlat(false);
return TRUE; // return TRUE unless you set the focus to a control
// 异常:OCX 属性页应返回 FALSE
}
void CComPropertyDlg::SetDCB(DCB* dcb)
{
this->m_pDcb = dcb;
}
void CComPropertyDlg::SetPortNum(int* pPort)
{
this->m_pPortNum = pPort;
}
void CComPropertyDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
/*1.串口
*/
CComboBox*pComb=NULL;
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO1);
if(pComb->GetCurSel()<0)
{
::AfxMessageBox("串口不能为空!");
return;
}
*this->m_pPortNum = pComb->GetCurSel()+1;
/*2.
*/
int index=-1;
int i=0;
CString value;
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO2);
index=pComb->GetCurSel();
if(index<0)
{
::AfxMessageBox("波特率不能为空!");
return;
}
pComb->GetLBText(index,value);
i=atoi(value);
this->m_pDcb->BaudRate = i;
/*3.
*/
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO3);
index=pComb->GetCurSel();
if(index<0)
{
::AfxMessageBox("数据位不能为空!");
return;
}
pComb->GetLBText(index,value);
i=atoi(value);
this->m_pDcb->ByteSize = i;
/*4.
*/
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO4);
index=pComb->GetCurSel();
if(index<0)
{
::AfxMessageBox("停止位不能为空!");
return;
}
this->m_pDcb->StopBits = index;
/*5.
*/
pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO5);
index=pComb->GetCurSel();
if(index<0)
{
::AfxMessageBox("校验不能为空!");
return;
}
this->m_pDcb->Parity = index;
OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -