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

📄 040410201leidlg.cpp

📁 SIMPLE语言编译器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 040410201leiDlg.cpp : implementation file
//

#include "stdafx.h"
#include "040410201lei.h"
#include "040410201leiDlg.h"
#include "table.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy040410201leiDlg dialog

CMy040410201leiDlg::CMy040410201leiDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy040410201leiDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy040410201leiDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy040410201leiDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy040410201leiDlg)
	DDX_Control(pDX, IDC_INCTRL, m_cIn);
	DDX_Control(pDX, IDC_OUTCTRL, m_cOut);
	DDX_Text(pDX, IDC_STATEBAR, m_cStateBar);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy040410201leiDlg, CDialog)
	//{{AFX_MSG_MAP(CMy040410201leiDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENUITEM_OPEN, OnMenuitemOpen)
	ON_COMMAND(ID_MENUITEM_EXIT, OnMenuitemExit)
	ON_COMMAND(ID_MENUITEM_CIFA, OnMenuitemCifa)
	ON_BN_CLICKED(IDC_BUTTON_CIFA, OnButtonCifa)
	ON_COMMAND(ID_MENUITEM_YUFA, OnMenuitemYufa)
	ON_BN_CLICKED(IDC_BUTTON_YUFA, OnButtonYufa)
	ON_COMMAND(ID_MENUITEM_YUYI, OnMenuitemYuyi)
	ON_BN_CLICKED(IDC_BUTTON_YUYI, OnButtonYuyi)
	ON_COMMAND(ID_MENUITEM_NEW, OnMenuitemNew)
	ON_COMMAND(ID_MENUITEM_SAVE, OnMenuitemSave)
	ON_COMMAND(ID_MENUITEM_SAVEAS, OnMenuitemSaveas)
	ON_EN_UPDATE(IDC_INCTRL, OnUpdateInctrl)
		ON_WM_CLOSE()
		ON_COMMAND(ID_TABLE_Fh, OnPrinter)
	ON_COMMAND(ID_MENUITEM_SYS, OnMenuitemSys)
		ON_UPDATE_COMMAND_UI(ID_MENUITEM_SYS, OnUpdateMenuitemSys)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy040410201leiDlg message handlers

BOOL CMy040410201leiDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_cIn.SetModify(FALSE);
	OnMenuitemNew();
	m_bSysEnable=TRUE;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy040410201leiDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMy040410201leiDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy040410201leiDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMy040410201leiDlg::OnMenuitemNew()
{
if (m_cIn.GetModify())
	{
		switch (AfxMessageBox("要保存修改吗?!",MB_YESNOCANCEL|MB_ICONQUESTION))
		{
		case IDYES:
			OnMenuitemSave();
			break;
		case IDCANCEL:
			return;
		default:
			;
		}
	}
    m_strCurFile="";
	m_cIn.SetSel(0,-1);
	m_cIn.Clear();
	m_cIn.EmptyUndoBuffer();
	SetWindowText("编译器  当前源文件:无标题");
    m_cIn.SetModify(FALSE);
}

void CMy040410201leiDlg::OnMenuitemSave()
{
if (m_strCurFile!="")
	{
		char buf[30001];
		int sz=m_cIn.GetWindowText(buf,30000);
		CFile f;
	    f.Open(m_strCurFile,CFile::modeWrite|CFile::modeCreate);
	    f.Write(buf,sz);
	    f.Close();
		char a[255];
		::strcpy(a,"编译器  当前源文件:");
		::strcat(a,m_strCurFile.GetBuffer(0));
		SetWindowText(a);
		m_cIn.SetModify(FALSE);
	}
	else
	{
		OnMenuitemSaveas();
	}
}

void CMy040410201leiDlg::OnMenuitemSaveas()
{
	CFileDialog fdlg(FALSE,"lei",NULL,OFN_OVERWRITEPROMPT,
		"源程序文件(*.lei)|*.lei|所有文件(*.*)|*.*||",this);
	fdlg.m_ofn.lpstrTitle="保存源程序文件";
	if (fdlg.DoModal()==IDOK)
	{
		m_strCurFile=fdlg.GetPathName();
		char buf[30001];
		int sz=m_cIn.GetWindowText(buf,30000);
		CFile f;
	    f.Open(m_strCurFile,CFile::modeWrite|CFile::modeCreate);
	    f.Write(buf,sz);
	    f.Close();
		m_cIn.SetModify(FALSE);
		char a[255];
		::strcpy(a,"编译器  当前源文件:");
		::strcat(a,m_strCurFile.GetBuffer(0));
		SetWindowText(a);
	}
}
/*
void CMy040410201leiDlg::OnMenuitemNew() 
{
	// TODO: Add your command handler code here
	
}
*/

void CMy040410201leiDlg::OnMenuitemOpen() 
{
	// TODO: Add your command handler code here
	if (m_cIn.GetModify())
	{
		switch (AfxMessageBox("要保存修改吗?!",MB_YESNOCANCEL|MB_ICONQUESTION))
		{
		case IDYES:
			OnMenuitemSave();
			break;
		case IDCANCEL:
			return;
		default:
			;
		}
	}
	CFileDialog fdlg(TRUE,"lei",NULL,OFN_FILEMUSTEXIST,
		"源程序文件(*.lei)|*.lei|所有文件(*.*)|*.*||",this);
    fdlg.m_ofn.lpstrTitle="打开源程序文件";
	if (fdlg.DoModal()==IDOK)
	{
		m_strCurFile=fdlg.GetPathName();
		CFile f;
		f.Open(m_strCurFile,CFile::modeRead);
		char buf[30001];
		int sz=f.Read(buf,30000);
		buf[sz]=0;
		m_cIn.SetWindowText(buf);
		m_cIn.SetSel(0,0);
		f.Close();
		char a[255];
		::strcpy(a,"编译器  当前源文件:");
		::strcat(a,m_strCurFile.GetBuffer(0));
		SetWindowText(a);
		m_cIn.SetModify(FALSE);
	}
}

void CMy040410201leiDlg::OnMenuitemExit() 
{
	// TODO: Add your command handler code here
	OnClose();
}

void CMy040410201leiDlg::OnClose()
{
if (m_cIn.GetModify())
	{

⌨️ 快捷键说明

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