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

📄 xiuhuadoc.cpp

📁 本程序用于读取电脑绣花机的数据
💻 CPP
字号:
// xiuhuaDoc.cpp : implementation of the CXiuhuaDoc class
//

#include "stdafx.h"
#include "xiuhua.h"

#include "xiuhuaDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaDoc

IMPLEMENT_DYNCREATE(CXiuhuaDoc, CDocument)

BEGIN_MESSAGE_MAP(CXiuhuaDoc, CDocument)
	//{{AFX_MSG_MAP(CXiuhuaDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaDoc construction/destruction

CXiuhuaDoc::CXiuhuaDoc()
{
	// TODO: add one-time construction code here
//增加初始化代码
	m_nBytesPerLine=2;//每行显示16个字节
	m_lFileLength=0L;
	m_pHexFile=NULL;
    
}

CXiuhuaDoc::~CXiuhuaDoc()
{ if (m_pHexFile !=NULL)
	{
		m_pHexFile->Close();
		delete m_pHexFile;
		m_pHexFile=NULL;
	}
}

BOOL CXiuhuaDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CXiuhuaDoc serialization

void CXiuhuaDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaDoc diagnostics

#ifdef _DEBUG
void CXiuhuaDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CXiuhuaDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaDoc commands

BOOL CXiuhuaDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{//文件打开命令自动调用“打开文件对话框,产生lpszPathName”,然后调用,OnOpenDocument(LPCTSTR lpszPathName) 
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// TODO: Add your specialized creation code here
	//编辑消息处理函数
	if(m_pHexFile!=NULL)//文件指针不为空,说明已有文件,
	{
		m_pHexFile->Close();//先关闭
		delete m_pHexFile;
	}//打开新文件
	m_pHexFile=new CFile(lpszPathName,CFile::modeRead|CFile::typeBinary);
	if (!m_pHexFile)
	{
		AfxMessageBox("文件打开出错!");
		return FALSE;
	}
 
	m_lFileLength=m_pHexFile->GetLength();//或得文件长度
	return TRUE;
}
BOOL CXiuhuaDoc::ReadFileAndProcess( long lOffset)
{
    long lPos;//定义文件读文件的指针,局部变量
	

	if (lOffset !=-1)
		lPos=m_pHexFile->Seek(lOffset,CFile::begin);
	else
		lPos=m_pHexFile->GetPosition();//文件指针为空,则指向文件头

	unsigned char szBuf[16];//用于读文件的缓冲
	
	int nRet =m_pHexFile->Read(szBuf,1);//读出当前指针处的数据
	
	return szBuf[0];

}

⌨️ 快捷键说明

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