📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "compile.h"
#include "MainFrm.h"
#include "compileView.h"
#include "errorView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//CFile f_in("file2.txt",CFile::shareDenyNone||CFile::modeReadWrite);
CFile f_result("result.txt",CFile::modeReadWrite);
CFile file_error("error.txt",CFile::modeReadWrite);
CString str;
////////////////////////////////////////
///////////////////////////////////////
int b=0;
#include"program.h"
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_STYLE, OnStyle)
ON_COMMAND(ID_BEGIN, OnBegin)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
if(!m_wndSplitter.CreateStatic(this,2,1))
return false;
//**Create two views and insert in to the splitter panes
if(!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CCompileView),CSize(600,320),pContext)||
!m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CerrorView),CSize(600,320),pContext))
//**注释:为切分窗口的每一个窗口创建一个视图。
{
m_wndSplitter.DestroyWindow();
//**注释:如果创建不成功,清除m_wndSplitter对象。
return false;
}
pView=(CEditView*)m_wndSplitter.GetPane(0,0);
dc=(CEditView*)m_wndSplitter.GetPane(1,0);
//**Return successful
CString title;
title.Format("编译器——周伟斌 制作");
SetTitle(title);
return true;
}
void CMainFrame::OnFileOpen()
{
// TODO: Add your command handler code here
CString strFileName;
CFileDialog dlg(true,NULL,NULL,0,"文本文件(*.TXT)|*.TXT||");//构造打开文件对话框
char byBuffer;
//CEditView * pView=(CEditView*)m_wndSplitter.GetPane(0,0);
if(dlg.DoModal()==IDOK) //显示打开文件对话框
{
strFileName=dlg.GetFileName();//获取文件路径名称
CFile MyFile(strFileName,CFile::modeReadWrite);
//char byBuffer;
if(strFileName!="*.TXT") //判断是否在打开文件对话框中选择了取消
{
while(MyFile.Read(&byBuffer,1)==1)
strText.operator +=(byBuffer);
pView->GetEditCtrl().SetWindowText(strText);
strText.Empty();
}else MessageBox("打开文件失败!","提示",MB_ICONHAND|MB_OK);
}
}
void CMainFrame::OnStyle()
{
// TODO: Add your command handler code here
//**Delete the CFontDialog
//注释:CfontDialog类包含了系统标准的CHOOSEFONT对话框,并且为用户选择字体和样式提
//供了一种更简单更灵活的方式。
CFontDialog dlgChooseFont;
//CEditView * pDC=(CEditView*)m_wndSplitter.GetPane(0,0);
if(dlgChooseFont.DoModal()==IDOK)
{
m_fnCustom.DeleteObject();
m_fnCustom.CreateFontIndirect(dlgChooseFont.m_cf.lpLogFont);
pView->SetFont(&m_fnCustom);
pView->GetEditCtrl().GetWindowText(strText);
pView->GetEditCtrl().SetWindowText(strText);
strText.Empty();
dc->SetFont(&m_fnCustom);
dc->GetEditCtrl().GetWindowText(strText);
dc->GetEditCtrl().SetWindowText(strText);
strText.Empty();
}
}
void CMainFrame::OnBegin()
{
// TODO: Add your command handler code here
char buffer;
b=0;
//int lenth=0,i;
pView->GetEditCtrl().GetWindowText(strText);
if(strText.GetLength()!=0)
{
if((fp=fopen("mid.txt","w+"))==NULL)
{
//printf("File can not be open\n");
//exit(0);
str.Format("failed%c%c",chr1,chr2);
f_result.Write(str,str.GetLength());
return;
}
//fseek(fp,0,SEEK_SET);
fwrite(strText,sizeof(char),strText.GetLength(),fp);
fwrite(".",sizeof(char),1,fp);
//fseek(fp,0,SEEK_SET);
f_result.SetLength(0);
file_error.SetLength(0);
begin();
strText.Empty();
f_result.SeekToBegin();
while(f_result.Read(&buffer,1)==1)
strText.operator +=(buffer);
pView->GetEditCtrl().SetWindowText(strText);
file_error.SeekToBegin();
strText.Empty();
while(file_error.Read(&buffer,1)==1)
strText.operator +=(buffer);
dc->GetEditCtrl().SetWindowText(strText);
strText.Empty();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -