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

📄 autodemoview.cpp

📁 自编的串口通信程序
💻 CPP
字号:
// AutoDemoView.cpp : implementation of the CAutoDemoView class
//

#include "stdafx.h"
#include "AutoDemo.h"

#include "AutoDemoDoc.h"
#include "AutoDemoView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAutoDemoView

IMPLEMENT_DYNCREATE(CAutoDemoView, CEditView)

BEGIN_MESSAGE_MAP(CAutoDemoView, CEditView)
	//{{AFX_MSG_MAP(CAutoDemoView)
	ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
	ON_WM_CHAR()
	ON_WM_KEYDOWN()
	ON_WM_CREATE()
	ON_WM_SHOWWINDOW()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_CONTROL_REFLECT_EX(EN_CHANGE, OnEditChange)
	ON_COMMAND_RANGE(ID_SET1,ID_SET2 ,OnSet1)
	ON_UPDATE_COMMAND_UI_RANGE(ID_SET1, ID_SET2,OnUpdateSet1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAutoDemoView construction/destruction

CAutoDemoView::CAutoDemoView()
{
	// TODO: add construction code here
	m_setCheck=ID_SET1;
}

CAutoDemoView::~CAutoDemoView()
{
}

BOOL CAutoDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CEditView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CAutoDemoView drawing

//void CAutoDemoView::OnDraw(CDC* pDC)
//{
//	CAutoDemoDoc* pDoc = GetDocument();
//	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
//}

/////////////////////////////////////////////////////////////////////////////
// CAutoDemoView diagnostics

#ifdef _DEBUG
void CAutoDemoView::AssertValid() const
{
	CView::AssertValid();
}

void CAutoDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CAutoDemoDoc* CAutoDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAutoDemoDoc)));
	return (CAutoDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAutoDemoView message handlers

void CAutoDemoView::OnChange() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CEditView::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CAutoDemoDoc *pDoc=(CAutoDemoDoc *)GetDocument();
	pDoc->SetModifiedFlag();
	
	CEdit &edit=GetEditCtrl();
	
	//edit.GetWindowText(pDoc->m_cmdStr.cmdStr);
	(pDoc)->m_cmdStr.cmdNumber=edit.GetLineCount();
	for(int i=0;i<pDoc->m_cmdStr.cmdNumber&&i<MAX_CMD_NUMBER;i++)
	{
		pDoc->m_cmdStr.cmdStr[i].length=
		edit.GetLine(i,(LPTSTR)(pDoc->m_cmdStr.cmdStr[i].str),MAX_CMD_STR_LENGTH+MAX_CMD_OPT_STR_LENGTH);	
		pDoc->m_cmdStr.cmdStr[i].str[pDoc->m_cmdStr.cmdStr[i].length]='\0';
	}

}


int CAutoDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CEditView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here

	return 0;
}

void CAutoDemoView::OnDestroy() 
{
	CEditView::OnDestroy();
	
	// TODO: Add your message handler code here
	CAutoDemoApp * pApp=(CAutoDemoApp *)::AfxGetApp();
	CDocument * pDoc=(CDocument *)(pApp->pDocTra);

	if(!pDoc)
		return;
	if (!pDoc->SaveModified())
		return;
    pApp->m_ScriptOpen=FALSE;
	// shut it down
	pDoc->OnCloseDocument();
		// this should destroy the document

}

void CAutoDemoView::OnSet1(UINT nID) 
{
	// TODO: Add your command handler code here
	m_setCheck=nID;
	
}

void CAutoDemoView::OnUpdateSet1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_setCheck==pCmdUI->m_nID)
		pCmdUI->SetCheck(1);
	else
		pCmdUI->SetCheck(0);

}

BOOL CAutoDemoView::CheckCommandEnd(CString &cmdString)
{
	BOOL res=FALSE;

	for(int i=0;i<cmdString.GetLength();i++)
	{
		if(cmdString.GetAt(i)=='\n'||cmdString.GetAt(i)=='\t')
			return TRUE;
	}
		return FALSE;
}

void CAutoDemoView::OnInitialUpdate() 
{
	CEditView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CString str;
	CAutoDemoDoc * pDoc=(CAutoDemoDoc *)GetDocument();
	for(int i=0;i<pDoc->m_cmdStr.cmdNumber;i++)
	   {
		str+=pDoc->m_cmdStr.cmdStr[i].str;
		str+="\r\n";
		}	
	this->SetWindowText(str);
		
}

⌨️ 快捷键说明

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