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

📄 my1view.cpp

📁 PL0的编译系统,使用MFC编写界面,采用浮动窗口来仿VC的环境
💻 CPP
字号:
// My1View.cpp : implementation of the CMy1View class
//

#include "stdafx.h"
#include "My1.h"
#include <afxwin.h>
#include "My1Doc.h"
#include "My1View.h"
#include "MainFrm.h"
#include <fstream.h>
#include <windef.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMy1View

IMPLEMENT_DYNCREATE(CMy1View, CEditView)

BEGIN_MESSAGE_MAP(CMy1View, CEditView)
	//{{AFX_MSG_MAP(CMy1View)
	ON_WM_CHAR()
	ON_WM_SETCURSOR()
	ON_WM_TIMER()
	ON_WM_CREATE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMy1View construction/destruction

CMy1View::CMy1View()
{
	// TODO: add construction code here
	mRow=1;
	mCol=1;			
}

CMy1View::~CMy1View()
{
	KillTimer(1);
}

BOOL CMy1View::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;
}

/////////////////////////////////////////////////////////////////////////////
// CMy1View drawing

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

/////////////////////////////////////////////////////////////////////////////
// CMy1View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMy1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMy1View message handlers
void CMy1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	/*int start,end;
	char buf[10];
	int col;
	CPoint c;

	start=this->GetEditCtrl().LineFromChar(-1);
	start++;
	if(nChar==VK_RETURN) start++;
	sprintf(buf,"%d行",start);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(2,buf,true)) 
		MessageBox("failed");
	this->GetEditCtrl().GetSel(start,end);	
	c=this->GetEditCtrl().PosFromChar(start-1);	
	col=c.x/8+1;
	if(nChar==VK_RETURN) col=1;
	sprintf(buf,"%d",col);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(3,buf,true)) 
		MessageBox("failed");*/
	char buf[10];

	if(nChar == VK_RETURN )
		{
		mRow++;
		mCol=1;
		}
	else
		{		
		mCol++;
		}
	sprintf(buf,"Ln %d",mRow);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(2,buf,true)) 
		MessageBox("failed");
	sprintf(buf,"Co %d",mCol);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(3,buf,true)) 
		MessageBox("failed");
	CEditView::OnChar(nChar, nRepCnt, nFlags);
}
void CMy1View::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
	/*char buf[10];

	sprintf(buf,"%d",mRow);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(2,buf,true)) 
		MessageBox("failed");
	sprintf(buf,"%d",mCol);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(3,buf,true)) 
		MessageBox("failed");	*/
	CEditView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

BOOL CMy1View::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	int start,end;	
	int col;
	char buf[10];
	CPoint c;

	start=this->GetEditCtrl().LineFromChar(-1);
	start++;	
	sprintf(buf,"Ln %d",start);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(2,buf,true)) 
		MessageBox("failed");
	this->GetEditCtrl().GetSel(start,end);	
	c=this->GetEditCtrl().PosFromChar(start-1);	
	col=c.x/8+1;	
	sprintf(buf,"Co %d",col);
	if(!((CMainFrame *)this->GetParentFrame())->m_wndStatusBar.SetPaneText(3,buf,true)) 
		MessageBox("failed");

	return CEditView::OnSetCursor(pWnd, nHitTest, message);
}

void CMy1View::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	static int x=-1;
	fstream infile,outfile;
	char buf[10];
	int line;

	infile.open("c://MyData.txt",ios::in | ios::nocreate);
	if(!infile) PostQuitMessage(0);
	else{
		infile.getline(buf,10);	
		sscanf(buf,"%d",&line);		
		if(line>=0)
			{
			SetFocus();
			int y=this->GetEditCtrl().LineIndex(line);	
			int z=this->GetEditCtrl().LineIndex(line+1);	
			this->GetEditCtrl().SetSel(y,z,false);
			}
		infile.close();	
		outfile.open("c://MyData.txt",ios::out);
		sprintf(buf,"%d",-1);
		outfile<<buf;
		outfile.close();
		CEditView::OnTimer(nIDEvent);
	}
	
}
int CMy1View::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CEditView::OnCreate(lpCreateStruct) == -1)
		return -1;	
	// TODO: Add your specialized creation code here
	fstream outfile;
	outfile.open("c://MyData.txt",ios::out);
	char buf[10];
	sprintf(buf,"%d",-1);
	outfile<<buf;
	outfile.close();
	SetTimer(1,100,NULL);
	return 0;
}

⌨️ 快捷键说明

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