dlgsenddataedit.cpp

来自「串口收发工具」· C++ 代码 · 共 153 行

CPP
153
字号
// DlgSendDataEdit.cpp : implementation file
//

#include "stdafx.h"
#include "maintain.h"
#include "DlgSendDataEdit1.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgSendDataEdit dialog
#include "mainfrm.h"
static BYTE bySendDataBuf[SEND_EDIT_LEN];
static int nSendDataLen = 0;

CDlgSendDataEdit::CDlgSendDataEdit(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSendDataEdit::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgSendDataEdit)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_doc = NULL;
}


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


BEGIN_MESSAGE_MAP(CDlgSendDataEdit, CDialog)
	//{{AFX_MSG_MAP(CDlgSendDataEdit)
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BTN_SENDN, OnBtnSendn)
	ON_BN_CLICKED(IDC_BTN_SENDSTOP, OnBtnSendstop)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgSendDataEdit message handlers

BOOL CDlgSendDataEdit::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect rc;
	GetClientRect(rc);
	int nWidth = rc.Width();
	int nHeight = rc.Height();
	
	int x = rc.left+15;
	int y = rc.top+10;
	int nEditWidth = nWidth-30;
	int nEditHeight = nHeight- 45;
	m_sendEdit.MoveWindow(x,y,nEditWidth,nEditHeight);
	m_sendEdit.SetFrameText(bySendDataBuf,nSendDataLen);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

int CDlgSendDataEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	m_sendEdit.Create(ES_AUTOVSCROLL|WS_CHILD|WS_VISIBLE|WS_BORDER|ES_UPPERCASE|ES_MULTILINE,
		CRect(0,0,0,0),this,IDW_DLGSENDDATAEDIT);
	return 0;
}

void CDlgSendDataEdit::OnBtnSend() 
{
	// TODO: Add your control notification handler code here
	m_sendEdit.GetData(buf,nLen);
	if(nLen>SEND_EDIT_LEN)
	{
		CString str;
		str.Format("发送字符长度超出%d个限制!",SEND_EDIT_LEN);
		MessageBox(str,"错误",MB_ICONEXCLAMATION );
		m_sendEdit.SetFocus();
		return;
	}
	memcpy(bySendDataBuf,buf,SEND_EDIT_LEN);
	nSendDataLen = nLen;

	m_doc = ((CMainFrame*)AfxGetMainWnd())->GetDoc();
	if(m_doc)
		m_doc->SendData(bySendDataBuf,nSendDataLen,true);
	
}

void CDlgSendDataEdit::OnCancel() 
{
	// TODO: Add extra cleanup here
	KillTimer(1);
	CDialog::OnCancel();
}

void CDlgSendDataEdit::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == 1)
		if(m_doc)
			m_doc->SendData(bySendDataBuf,nSendDataLen,true);
	CDialog::OnTimer(nIDEvent);
}

void CDlgSendDataEdit::OnDestroy() 
{
	CDialog::OnDestroy();
	
	KillTimer(1);
}

void CDlgSendDataEdit::OnBtnSendn() 
{
	// TODO: Add your control notification handler code here
	m_sendEdit.GetData(buf,nLen);
	if(nLen>SEND_EDIT_LEN)
	{
		CString str;
		str.Format("发送字符长度超出%d个限制!",SEND_EDIT_LEN);
		MessageBox(str,"错误",MB_ICONEXCLAMATION );
		m_sendEdit.SetFocus();
		return;
	}
	memcpy(bySendDataBuf,buf,SEND_EDIT_LEN);
	nSendDataLen = nLen;

	m_doc = ((CMainFrame*)AfxGetMainWnd())->GetDoc();
	
	SetTimer(1,1000,NULL);
}

void CDlgSendDataEdit::OnBtnSendstop() 
{
	// TODO: Add your control notification handler code here
	KillTimer(1);
}

⌨️ 快捷键说明

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