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

📄 setupdlg.cpp

📁 VC6 多线程的串口操作
💻 CPP
字号:
// SetupDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Terminal.h"
#include "SetupDlg.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_nBaud = -1;
	m_nDataBits = -1;
	m_bEcho = FALSE;
	m_nFlowCtrl = -1;
	m_bNewLine = FALSE;
	m_nStopBits = -1;
	m_nPort = -1;
	m_nParity = -1;
	//}}AFX_DATA_INIT
}


void CSetupDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetupDlg)
	DDX_CBIndex(pDX, IDC_BAUD, m_nBaud);
	DDX_CBIndex(pDX, IDC_DATABITS, m_nDataBits);
	DDX_Check(pDX, IDC_ECHO, m_bEcho);
	DDX_Radio(pDX, IDC_FLOWCTRL, m_nFlowCtrl);
	DDX_Check(pDX, IDC_NEWLINE, m_bNewLine);
	DDX_CBIndex(pDX, IDC_STOPBITS, m_nStopBits);
	DDX_CBIndex(pDX, IDC_PORT, m_nPort);
	DDX_CBIndex(pDX, IDC_PARITY, m_nParity);
	//}}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
	GetDlgItem(IDOK)->EnableWindow(!m_bConnected);
/*
	CFileFind fd;
	if(!fd.FindFile(::GetCommDataFileName())){
		CFile cf;
		cf.Open(GetCommDataFileName(),CFile::modeCreate|CFile::modeWrite);
		CArchive ar(&cf,0,4096,NULL);
		Serialize(ar);
		ar.Close();
		cf.Close();
	}
	else{
		CFile cf;
		cf.Open(GetCommDataFileName(),CFile::modeRead);
		CArchive ar(&cf,1,4096,NULL);
		Serialize(ar);
		ar.Close();
		cf.Close();
	}
	fd.Close();
*/
	m_strPort=AfxGetApp()->GetProfileString("Serial Port Set","m_strPort");
	m_strBaud=AfxGetApp()->GetProfileString("Serial Port Set","m_strBaud");
	m_strDataBits=AfxGetApp()->GetProfileString("Serial Port Set","m_strDataBits");
	m_nPort=AfxGetApp()->GetProfileInt("Serial Port Set","m_nPort",0);
	m_nBaud=AfxGetApp()->GetProfileInt("Serial Port Set","m_nBaud",0);
	m_nDataBits=AfxGetApp()->GetProfileInt("Serial Port Set","m_nDataBits",0);
	m_nParity=AfxGetApp()->GetProfileInt("Serial Port Set","m_nParity",0);
	m_nStopBits=AfxGetApp()->GetProfileInt("Serial Port Set","m_nStopBits",0);
	m_nFlowCtrl=AfxGetApp()->GetProfileInt("Serial Port Set","m_nFlowCtrl",0);
	m_bEcho=AfxGetApp()->GetProfileInt("Serial Port Set","m_bEcho",0);
	m_bNewLine=AfxGetApp()->GetProfileInt("Serial Port Set","m_bNewLine",0);
	UpdateData(FALSE);
	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

	UpdateData(TRUE);
	m_strPort=GetCBText(IDC_PORT,m_nPort);
	m_strBaud=GetCBText(IDC_BAUD,m_nBaud);
	m_strDataBits=GetCBText(IDC_DATABITS,m_nDataBits);
/*
    strText.Format("%04d %04d %04d %04d",
                   wndpl.rcNormalPosition.left,
                   wndpl.rcNormalPosition.top,
                   wndpl.rcNormalPosition.right,
                   wndpl.rcNormalPosition.bottom);
    AfxGetApp()->WriteProfileString(s_profileHeading,
                                    s_profileRect, strText);
    AfxGetApp()->WriteProfileInt(s_profileHeading,
                                 s_profileIcon, bIconic);
    AfxGetApp()->WriteProfileInt(s_profileHeading,
                                 s_profileMax, bMaximized);
    SaveBarState(AfxGetApp()->m_pszProfileName);
*/
	AfxGetApp()->WriteProfileString("Serial Port Set","m_strPort",m_strPort);
	AfxGetApp()->WriteProfileString("Serial Port Set","m_strBaud",m_strBaud);
	AfxGetApp()->WriteProfileString("Serial Port Set","m_strDataBits",m_strDataBits);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_nPort",m_nPort);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_nBaud",m_nBaud);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_nDataBits",m_nDataBits);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_nParity",m_nParity);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_nStopBits",m_nStopBits);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_nFlowCtrl",m_nFlowCtrl);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_bEcho",m_bEcho);
	AfxGetApp()->WriteProfileInt("Serial Port Set","m_bNewLine",m_bNewLine);
	//AfxGetApp()->WriteProfileBinary("Serial Port Set","Binary",(UCHAR*)m_strPort.GetBuffer(6),6);
/*
	CFile cf;
	cf.Open(GetCommDataFileName(),CFile::modeWrite);
	CArchive ar(&cf,0,4096,NULL);
	Serialize(ar);
	ar.Close();
	cf.Close();
*/
	CDialog::OnOK();
}
/*
void CSetupDlg::Serialize(CArchive& ar) 
{
	if (ar.IsStoring())
	{	// storing code
		ar<<m_nPort;
		ar<<m_strPort;
		ar<<m_nBaud;
		ar<<m_strBaud;
		ar<<m_nDataBits;
		ar<<m_strDataBits;
		ar<<m_nParity;
		ar<<m_nStopBits;
		ar<<m_nFlowCtrl;
		ar<<m_bEcho;
		ar<<m_bNewLine;
	}
	else
	{	// loading code
		ar>>m_nPort;
		ar>>m_strPort;
		ar>>m_nBaud;
		ar>>m_strBaud;
		ar>>m_nDataBits;
		ar>>m_strDataBits;
		ar>>m_nParity;
		ar>>m_nStopBits;
		ar>>m_nFlowCtrl;
		ar>>m_bEcho;
		ar>>m_bNewLine;
	}
}
*/
CString CSetupDlg::GetCBText(int nIDCombo, int nIndex)
{
	CString rstr;
	CComboBox* pComboBox=(CComboBox *)GetDlgItem(nIDCombo);
	pComboBox->GetLBText(nIndex,rstr);
	return rstr;
}
/*
int CSetupDlg::GetCBIndex(int nID, CString string)
{
	//CComboBox *pComboBox=(CComboBox *)GetDlgItem(nID);
	return ((CComboBox *)GetDlgItem(nID))->FindString(0,string);

}*/

⌨️ 快捷键说明

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