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

📄 microinsdlg.cpp

📁 模拟了tec2000的所有功能
💻 CPP
字号:
// MicroInsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TEC2000.h"
#include "MicroInsDlg.h"
#include<fstream.h>

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

/////////////////////////////////////////////////////////////////////////////
// CMicroInsDlg dialog


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


void CMicroInsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMicroInsDlg)
	DDX_Control(pDX, IDC_MIC_EDIT, m_ctrlEditIns);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMicroInsDlg, CDialog)
	//{{AFX_MSG_MAP(CMicroInsDlg)
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMicroInsDlg message handlers

void CMicroInsDlg::OnOpen() 
{
	char buffer[256];
	CString context;


    GetCurrentDirectory(200,buffer);
	CString temp1="\\MicroIns.txt";
	char buffer1[20];
	strcpy(buffer1,temp1);
	strcat(buffer,buffer1);


	fstream in_file;
	in_file.open(buffer,ios::out||ios::in);
	while(in_file.eof()==0){
    	in_file.getline(buffer,256,'\n');
    	context+=buffer;
		context+="\r\n";
	}
	in_file.close();

	m_ctrlEditIns.SetWindowText(context);
	
}

void CMicroInsDlg::OnSave() 
{
	char buf[69];
	buf[68]='\0';
	int lines=m_ctrlEditIns.GetLineCount();
   
	for(int i=0;i<lines-2;i++)
	{
		m_ctrlEditIns.GetLine(i,buf,68);
		int len=strlen(buf);
		CString temp;
		temp.Format("%d",len);

		if(len<68){
			CString str1;
		    str1.Format("%d",i);
	        str1+="列:";
	        str1+="有误\r\n数据恢复到改之前";
	        ::MessageBox(0,str1,0,0);
	    	OnOpen();
		    return ; 
		}
		if(buf[0]==' '&&buf[1]==' '){
			if(  (buf[2]!=' ') || (!(checkhex(buf[3])))  ||  
				                  (!(checkhex(buf[4])))  || (buf[5]!=' ')  	 )
			{
              	CString str1;
		        str1.Format("%d",i);
	            str1+="列:";
	     	    str1+="pc有误\r\n数据恢复到改之前";
	    	    ::MessageBox(0,str1,0,0);
				OnOpen();
			    return ;  
		   }
		   if( ! ( (checkhex(buf[6]))&& (checkhex(buf[7]))	 ) )
		   {
              	CString str1;
		        str1.Format("%d",i);
	            str1+="列:";
	     	    str1+="nx有误\r\n数据恢复到改之前";
	    	    ::MessageBox(0,str1,0,0);
                OnOpen();       
			    return ; 
		   }
		   for(int i1=0;i1<12;i1++)
		   {
			   for(int k=0;k<4;k++)
			   {
				   char ch;
				   ch=buf[9+i1*5+k];   
		           if(!(ch=='0'||ch=='1'))
				   {
                    	CString str1;
		                str1.Format("%d",i);
	                    str1+="列:第";
                    	CString str;
		                str.Format("%d",i1);
			         	str1+=str;
			        	str1+="个字段";
	     	            str1+="有误\r\n数据恢复到改之前";
	    	            ::MessageBox(0,str1,0,0);
						OnOpen();
						return ; 
				   }			   
			   }
		       
			   if(buf[7+(i1-1)*4+i1+5]!=' ')
			   {
				    CString str1;
		            str1.Format("%d",i);
	                str1+="列:第";
                    CString str;
		            str.Format("%d",i1);
			    	str1+=str;
			    	str1+="个字段";
	     	        str1+="后面的空格有误\r\n数据恢复到改之前";
	    	       ::MessageBox(0,str1,0,0);  
				   OnOpen();
				   return ; 
			   }       
		   }

		}
		if(buf[1]==' '){
		}
		else
		{
			if( !((checkhex(buf[0]))&&(checkhex(buf[1])))  )
			{
				CString str1;
		        str1.Format("%d",i);
	            str1+="列:";
	     	    str1+="操作码有误\r\n数据恢复到改之前";
	    	    ::MessageBox(0,str1,0,0);  
				OnOpen();
			    return  ;   
			}
			if(  (buf[2]!=' ') || (!(checkhex(buf[3])))  ||  
				                  (!(checkhex(buf[4])))  || (buf[5]!=' ')  	 )
			{
              	CString str1;
		        str1.Format("%d",i);
	            str1+="列:";
	     	    str1+="pc有误\r\n数据恢复到改之前";
	    	    ::MessageBox(0,str1,0,0);
				OnOpen();
			    return ;  
		   }
		   if( ! ( (checkhex(buf[6]))&& (checkhex(buf[7]))	 ) )
		   {
              	CString str1;
		        str1.Format("%d",i);
	            str1+="列:";
	     	    str1+="nx有误\r\n数据恢复到改之前";
	    	    ::MessageBox(0,str1,0,0);
                OnOpen();       
			    return ; 
		   }
           
		   for(int i1=0;i1<12;i1++)
		   {
			   for(int k=0;k<4;k++)
			   {
				   char ch;
				   ch=buf[9+i1*5+k];   
		           if(!(ch=='0'||ch=='1'))
				   {
                    	CString str1;
		                str1.Format("%d",i);
	                    str1+="列:第";
                    	CString str;
		                str.Format("%d",i1);
			         	str1+=str;
			        	str1+="个字段";
	     	            str1+="有误\r\n数据恢复到改之前";
	    	            ::MessageBox(0,str1,0,0);
						OnOpen();
						return ; 
				   }			   
			   } 
			   if(buf[7+(i1-1)*4+i1+5]!=' ')
			   {
				    CString str1;
		            str1.Format("%d",i);
	                str1+="列:第";
                    CString str;
		            str.Format("%d",i1);
			    	str1+=str;
			    	str1+="个字段";
	     	        str1+="后面的空格有误\r\n数据恢复到改之前";
	    	       ::MessageBox(0,str1,0,0);  
				   OnOpen();
				   return ; 
			   }       
		   }
		}
	}





    CString context;
	m_ctrlEditIns.GetWindowText(context);

//	AfxMessageBox(context);

    char buffer[256];
	GetCurrentDirectory(200,buffer);
	CString temp1="\\MicroIns.txt";
	char buffer1[20];
	strcpy(buffer1,temp1);
	strcat(buffer,buffer1);

//	AfxMessageBox(buffer);
	fstream in_file;
//	CFile in_file;
//	in_file.Open(buffer);
	in_file.open(buffer,ios::out|ios::in);
	in_file.clear();
//	in_file.clear(true);
	char temp[5000];
	strcpy(temp,context);
	AfxMessageBox(context);
	AfxMessageBox(temp);
	in_file<<temp;
//	in_file<<"fjsfs";
	in_file.close();


	


	
}



bool CMicroInsDlg::checkhex(char ch)
{
	if(ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'
		||ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='0'
	||ch=='A'||ch=='B'||ch=='C'||ch=='D'||ch=='E'||ch=='F'
	||ch=='a'||ch=='b'||ch=='c'||ch=='d'||ch=='e'||ch=='f')
	return 1;
	else return 0;
}


int CMicroInsDlg::HaveIns(char *ch){
	char buf[69];
	buf[68]='\0';
	char ins[3];
	int sign=1;
	int lines=m_ctrlEditIns.GetLineCount();
	for(int i=0;i<lines-2;i++)
	{
		m_ctrlEditIns.GetLine(i,buf,68);
		ins[0]=buf[3];
		ins[1]=buf[4];
		ins[2]='\0';
		sign=strcmp(ins,ch);
		if(sign==0)
			return 1;
	}
	return 0;
}

void CMicroInsDlg::DelIns(){
	char buffer[256];

	int sign;
	GetCurrentDirectory(200,buffer);
	CString temp1="\\ins.txt";
	char buffer1[20];
	strcpy(buffer1,temp1);
	strcat(buffer,buffer1);
	char ins[3];
	char buf[20];
	CString context;
	ifstream in_file(buffer,ios::in||ios::out);
	while(in_file.eof()==0){
    	in_file.getline(buf,20,'\n');
    	ins[0]=buf[3];
    	ins[1]=buf[4];
    	ins[2]='\0';
    	sign=HaveIns(ins);
		if(sign==1){
			context+=buf;
			context+="\r\n";
		}

	}
//	in_file.
}
	

⌨️ 快捷键说明

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