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

📄 comsetting.cpp

📁 南瑞xt9702规约
💻 CPP
字号:
// ComSetting.cpp : implementation file
//

#include "stdafx.h"
#include "Xt9702Slave.h"
#include "ComSetting.h"

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

/////////////////////////////////////////////////////////////////////////////
// CComSetting dialog


CComSetting::CComSetting(CWnd* pParent /*=NULL*/)
	: CDialog(CComSetting::IDD, pParent)
{
	//{{AFX_DATA_INIT(CComSetting)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pComNo = NULL;
	m_pBaud = NULL;
	m_pData = NULL;
	m_pStop = NULL;
	m_pParity = NULL;

	m_pStaticComNo = NULL;
	m_pStaticBaud = NULL;
	m_pStaticData = NULL;
	m_pStaticStop = NULL;
	m_pStaticParity = NULL;

	m_pOk = NULL;
	m_pCancel = NULL;

	m_strStopBit = 0;
	m_strParity = 0;
	m_Stop = 0;
	m_Parity = 0;
	memset( &m_strComNo, '\0', sizeof( m_strComNo ) );
	memset( &m_strBaudRate, '\0', sizeof( m_strBaudRate ) );
	memset( &m_strDataSize, '\0', sizeof( m_strDataSize ) );
}

CComSetting::~CComSetting()
{
	if( m_pComNo ) delete m_pComNo;
	if( m_pBaud ) delete m_pBaud;
	if( m_pData ) delete m_pData;
	if( m_pStop ) delete m_pStop;
	if( m_pParity ) delete m_pParity;

	if( m_pStaticComNo ) delete m_pStaticComNo;
	if( m_pStaticBaud ) delete m_pStaticBaud;
	if( m_pStaticData ) delete m_pStaticData;
	if( m_pStaticStop ) delete m_pStaticStop;
	if( m_pStaticParity ) delete m_pStaticParity;

	if( m_pOk ) delete m_pOk;
	if( m_pCancel ) delete m_pCancel;
}

void CComSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CComSetting)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CComSetting message handlers

BOOL CComSetting::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect	rect;
	GetClientRect( rect );
	rect.top += 10;
	rect.left += 10;
	m_pStaticComNo = new CStatic;
	m_pStaticComNo->Create( _T( "串口号:" ), WS_CHILD | WS_VISIBLE, rect, this, 12345 );
	m_pStaticComNo->SetFont( GetFont() );
	rect.top += 20;
	m_pStaticBaud = new CStatic;
	m_pStaticBaud->Create( _T( "波特率:" ), WS_CHILD | WS_VISIBLE, rect, this, 12345 );
	m_pStaticBaud->SetFont( GetFont() );
	rect.top += 20;
	m_pStaticData = new CStatic;
	m_pStaticData->Create( _T( "数据位:" ), WS_CHILD | WS_VISIBLE, rect, this, 12345 );
	m_pStaticData->SetFont( GetFont() );
	rect.top += 20;
	m_pStaticStop = new CStatic;
	m_pStaticStop->Create( _T( "停止位:" ), WS_CHILD | WS_VISIBLE, rect, this, 12345 );
	m_pStaticStop->SetFont( GetFont() );
	rect.top += 20;
	m_pStaticParity = new CStatic;
	m_pStaticParity->Create( _T( "校验位:" ), WS_CHILD | WS_VISIBLE, rect, this, 12345 );
	m_pStaticParity->SetFont( GetFont() );

	GetClientRect( rect );
	rect.top += 5;
	rect.left += 65;
	rect.right -= 10;
	rect.bottom += 50;
	m_pComNo = new CComboBox;
	m_pComNo->Create( WS_VSCROLL | CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_TABSTOP, rect, this, 123456 );
	m_pComNo->SetFont( GetFont() );
	rect.top += 20;
	m_pBaud = new CComboBox;
	m_pBaud->Create( WS_VSCROLL | CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_TABSTOP, rect, this, 123456 );
	m_pBaud->SetFont( GetFont() );
	rect.top += 20;
	m_pData = new CComboBox;
	m_pData->Create( WS_VSCROLL | CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_TABSTOP, rect, this, 123456 );
	m_pData->SetFont( GetFont() );
	rect.top += 20;
	m_pStop = new CComboBox;
	m_pStop->Create( WS_VSCROLL | CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_TABSTOP, rect, this, 123456 );
	m_pStop->SetFont( GetFont() );
	rect.top += 20;
	m_pParity = new CComboBox;
	m_pParity->Create( WS_VSCROLL | CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_TABSTOP, rect, this, 123456 );
	m_pParity->SetFont( GetFont() );

	rect.left = 10;
	rect.right/=2;
	rect.top += 25;
	rect.bottom -= 60;
	m_pOk = new CButtonEx;
	m_pOk->Create( _T( "确定" ), WS_CHILD | WS_VISIBLE | BS_FLAT, rect, this, IDOK );
	m_pOk->SetFont( GetFont() );
	m_pOk->SetIcon( IDI_OK, (int)BTNST_AUTO_GRAY );
	
	rect.left += rect.right;
	rect.right += rect.right;
	m_pCancel = new CButtonEx;
	m_pCancel->Create( _T( "取消" ), WS_CHILD | WS_VISIBLE | BS_FLAT, rect, this, IDCANCEL );
	m_pCancel->SetFont( GetFont() );
	m_pCancel->SetIcon( IDI_CANCEL, (int)BTNST_AUTO_GRAY );

	CreateFile();

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

void CComSetting::CreateFile()
{
	int		i;
	char	text[128];
	char*	BaudRate[] = { "110", "300", "600", "1200", "2400", "4800", "9600", "19200" };
	char*	DataSize[] = { "5", "6", "7", "8" };
	char*	Parity[] = { "NONE", "ODD", "EVEN" };
	char*	StopBit[] = { "1", "1.5", "2" };
	for( i = 0; i < 10; i++ ) {
		sprintf( text, "COM%d", i+1 );
		m_pComNo->AddString( (LPCTSTR)text );
	}
	if( m_strComNo != "" ) m_pComNo->SetWindowText( m_strComNo );
	else m_pComNo->SetCurSel( 0 );
	m_pComNo->EnableWindow( !m_bConnected );
	for( i = 0; i < 8; i++ ) {
		m_pBaud->AddString( (LPCTSTR)BaudRate[i] );
	}
	if( m_strBaudRate != "" ) m_pBaud->SetWindowText( m_strBaudRate );
	else m_pBaud->SetCurSel( 6 );
	for( i = 0; i < 4; i++ ) {
		m_pData->AddString( (LPCTSTR)DataSize[i] );
	}
	if( m_strDataSize != "" ) m_pData->SetWindowText( m_strDataSize );
	else m_pData->SetCurSel( 3 );
	for( i = 0; i < 3; i++ ) {
		m_pStop->AddString( (LPCTSTR)StopBit[i] );
	}
	m_pStop->SetCurSel( m_Stop );
	for( i = 0; i < 3; i++ ) {
		m_pParity->AddString( (LPCTSTR)Parity[i] );
	}
	m_pParity->SetCurSel( m_Parity );
}

void CComSetting::OnOK()
{
	int		nIdex;
	CString	str;
	m_pComNo->GetWindowText( str );
	strcpy( m_strComNo, str.GetBuffer( 0 ) );
	m_pBaud->GetWindowText( str );
	strcpy( m_strBaudRate, str.GetBuffer( 0 ) );
	m_pData->GetWindowText( str );
	strcpy( m_strDataSize, str.GetBuffer( 0 ) );
	
	nIdex = m_pStop->GetCurSel();
	switch( nIdex ) {
	case 0:	m_strStopBit = ONESTOPBIT;		break;
	case 1:	m_strStopBit = ONE5STOPBITS;	break;
	case 2:	m_strStopBit = TWOSTOPBITS;		break;
	default:	m_strStopBit = ONESTOPBIT;	break;
	}

	nIdex = m_pParity->GetCurSel();
	switch( nIdex )	{
	case 0:	m_strParity = NOPARITY;		break;
	case 1:	m_strParity = ODDPARITY;	break;
	case 2:	m_strParity = EVENPARITY;	break;
	default:	m_strParity = NOPARITY;	break;
	}
	CDialog::OnOK();
}

⌨️ 快捷键说明

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