?? 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 + -