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

📄 hlaview.cpp

📁 一个HLA(高级汇编)程序的界面的封装
💻 CPP
字号:
// hlaView.cpp : implementation of the CHlaView class
//

#include "stdafx.h"
#include "hla.h"

#include "hlaDoc.h"
#include "hlaView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHlaView

IMPLEMENT_DYNCREATE(CHlaView, CEditView)

BEGIN_MESSAGE_MAP(CHlaView, CEditView)
	//{{AFX_MSG_MAP(CHlaView)
	ON_COMMAND(IDC_BUILD, OnBuild)
	ON_COMMAND(IDC_RUN, OnRun)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHlaView construction/destruction

CHlaView::CHlaView()
{
	// TODO: add construction code here
	path="";
	na="";
	pathname="";
	flag=0;
}

CHlaView::~CHlaView()
{
}

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

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CHlaView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CHlaView printing

BOOL CHlaView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CHlaView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CHlaView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CHlaView diagnostics

#ifdef _DEBUG
void CHlaView::AssertValid() const
{
	CEditView::AssertValid();
}

void CHlaView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CHlaView message handlers

void CHlaView::OnBuild() 
{
	// TODO: Add your command handler code here
	CString str;
	char Buf[100];
	flag=1;
	if(path==""|na==""|pathname=="")
	{
		MessageBox("请先保存!","提示!",MB_OK);
		return;
	}
	GetWindowText(str);
	CFile file(path,CFile::modeWrite|CFile::modeCreate);
	GetWindowText(str);
	file.Write(str.GetBuffer(str.GetLength()),str.GetLength());
	file.Close();
	CFile batfile(pathname+".bat",CFile::modeWrite|CFile::modeCreate);
	sprintf(Buf,"@hla %s.hla\r\n@pause",pathname.GetBuffer(pathname.GetLength()));
	batfile.Write(Buf,strlen(Buf));
	batfile.Close();
	PROCESS_INFORMATION pi;
	STARTUPINFO sui;
	ZeroMemory(&sui,sizeof(STARTUPINFOW));
	CreateProcess(pathname+".bat",NULL,NULL,NULL,
		true,0,NULL,NULL,&sui,&pi);
}

void CHlaView::OnRun() 
{
	// TODO: Add your command handler code here
	char Buf[100];
	CString str;
	if(path==""|na=="")
	{
		MessageBox("请先保存!","提示!",MB_OK);
		return;
	}
	GetWindowText(str);
	CFile file(path,CFile::modeWrite|CFile::modeCreate);
	GetWindowText(str);
	file.Write(str.GetBuffer(str.GetLength()),str.GetLength());
	file.Close();
	CFile batrunfile(pathname+"run.bat",CFile::modeWrite|CFile::modeCreate);
	sprintf(Buf,"%s\r\npause",pathname.GetBuffer(pathname.GetLength()));
	batrunfile.Write(Buf,strlen(Buf));
	batrunfile.Close();
	if(flag==1)
	{
		PROCESS_INFORMATION pi;
		STARTUPINFO sui;
	    ZeroMemory(&sui,sizeof(STARTUPINFOW));
		CreateProcess(pathname+"run.bat",NULL,NULL,NULL,
			TRUE,0,NULL,NULL,&sui,&pi);
		flag=0;
	}
	else
		MessageBox("请先链接!");
}

void CHlaView::OnFileOpen() 
{
	// TODO: Add your command handler code here
	CString str;
	char Buf[5000];
	CFileDialog fd(TRUE,NULL,NULL,OFN_FILEMUSTEXIST,"project (*.hla)|*.hla||");
	if(IDOK==fd.DoModal())
	{	
		CFile file(fd.GetPathName(),CFile::modeRead);
		Buf[file.GetLength()+1]='\0';
		file.Read(Buf,file.GetLength());
		file.Close();
		str=Buf;
		SetWindowText(str);
	}
}

void CHlaView::OnFileSave() 
{
	// TODO: Add your command handler code here
	
	CString str;
	GetWindowText(str);
	CFileDialog fd(false,NULL,NULL,OFN_FILEMUSTEXIST,"project (*.hla)|*.hla||");
	if(IDOK==fd.DoModal())
	{
		pathname=fd.GetPathName();
		if(pathname.Right(4)==".hla")
			pathname=pathname.Left(pathname.Find(".hla"));
		path=fd.GetPathName();
        na=fd.GetFileName();
//		MessageBox(na);
		if(na.Right(4)!=".hla")
			path=path+".hla";
		CFile file(path,CFile::modeWrite|CFile::modeCreate);
		GetWindowText(str);
		file.Write(str.GetBuffer(str.GetLength()),str.GetLength());
		file.Close();
	} 
    
}

⌨️ 快捷键说明

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