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

📄 editpad.cpp

📁 一个完整的编辑器的代码(很值得参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////
//  File:    editpad.cpp
//  Version: 1.1.0.4
//  Updated: 19-Jul-1998
//
//  Copyright:  Ferdinand Prantl, portions by Stcherbatchenko Andrei
//  E-mail:     prantl@ff.cuni.cz
//
//  Application core
//
//  You are free to use or modify this code to the following restrictions:
//  - Acknowledge me somewhere in your about box, simple "Parts of code by.."
//  will be enough. If you can't (or don't want to), contact me personally.
//  - LEAVE THIS HEADER INTACT
////////////////////////////////////////////////////////////////////////////

// editpad.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "editpad.h"

#include "mainfrm.h"
#include "editpaddoc.h"
#include "editpadview.h"
#include "epricdoc.h"
#include "epricvw.h"
#include "epbindoc.h"
#include "epbinvw.h"
#include "editcmd.h"
#include "memcombo.h"
#include "registry.h"
#include "editreg.h"
#include "splash.h"
#include "tipdlg.h"
#include "aboutdlg.h"
#include "edfopdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEditPadApp

BEGIN_MESSAGE_MAP (CEditPadApp, CWinApp)
//{{AFX_MSG_MAP(CEditPadApp)
ON_COMMAND (ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_HELP_TIPOFTHEDAY, OnTipOfTheDay)
ON_UPDATE_COMMAND_UI (ID_TOOLS_SPELLING_SET, OnUpdateToolsSpellingSet)
ON_COMMAND (ID_TOOLS_SPELLING_SET, OnToolsSpellingSet)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND (ID_FILE_NEW, OnFileNew)
ON_COMMAND (ID_FILE_OPEN, OnFileOpen)
// Standard print setup command
ON_COMMAND (ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP ()

/////////////////////////////////////////////////////////////////////////////
// CEditPadApp construction

CEditPadApp::CEditPadApp () : m_dwFlags (EP_SAVE_SETS_ON_EXIT|EP_NOTIFY_CHANGES|EP_ADVANCED_UI|EP_REMEMBER_LASTPOS)
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

DWORD CEditPadApp::
GetFlags ()
{
	return m_dwFlags;
}

void CEditPadApp::
SetFlags (DWORD dwFlags)
{
	if (m_dwFlags != dwFlags)
		{
			m_dwFlags = dwFlags;
		}
}

void CEditPadApp::
LoadSettings ()
{
  CEditPadView::LoadSettings ();
  CMemComboBox::LoadSettings ();
  *CEditPadView::szWIspellPath = _T ('\0');
  CReg reg;
  if (reg.Open (HKEY_CURRENT_USER, REG_EDITPAD_SINGLE, KEY_READ))
    {
      reg.LoadString (_T ("LastFile"), m_sLastDoc);
      reg.LoadNumber (_T ("Flags"), &m_dwFlags);
    }
  reg.Close ();
  if (reg.Open (HKEY_CURRENT_USER, REG_EDITPAD, KEY_READ))
    {
      reg.LoadString (_T ("WIspellPath"), CEditPadView::szWIspellPath, _MAX_PATH);
    }
}

void CEditPadApp::
LoadLastDoc ()
{
	if (!m_sLastDoc.IsEmpty ())
		{
			OpenDocumentFile (m_sLastDoc);
			m_sLastDoc.Empty ();
		}
}

void CEditPadApp::
SaveSettings ()
{
	CEditPadView::SaveSettings ();
	CMemComboBox::SaveSettings ();
	CReg reg;
	if (reg.Create (HKEY_CURRENT_USER, REG_EDITPAD_SINGLE, KEY_WRITE))
		{
      VERIFY (reg.SaveString (_T ("LastFile"), m_sLastDoc));
			VERIFY (reg.SaveNumber (_T ("Flags"), m_dwFlags));
		}
  reg.Close ();
  if (reg.Create (HKEY_CURRENT_USER, REG_EDITPAD, KEY_WRITE))
    {
      VERIFY (reg.SaveString (_T ("WIspellPath"), CEditPadView::szWIspellPath));
    }
  reg.Close ();
  struct
    {
      TCHAR path [_MAX_PATH];
      time_t stamp;
    } oOdd[REMEMBERED_TO_REMOVE];
  time_t stamp;
  time (&stamp);
  stamp += 1000;
  int i;
  for (i = 0; i < REMEMBERED_TO_REMOVE; i++)
    oOdd[i].stamp = stamp;
  CString sKey = REG_EDITPAD;
  sKey += _T ("\\Remembered");
  DWORD nEntries;
  LPCTSTR pszPath;
  RegVal vValue;
  if (reg.Open (HKEY_CURRENT_USER, sKey, KEY_READ|KEY_WRITE) && reg.HasEntries (NULL, &nEntries) && nEntries > MAX_REMEMBERED && reg.FindFirstValue (pszPath, &vValue))
    {
      DWORD dwLastPos[3];
      int nDelta, nMaxDelta, nPos;
      do
        {
          if (RegValGetBinary (&vValue, (LPBYTE) dwLastPos, sizeof (dwLastPos)))
            {
              nMaxDelta = 0;
              nPos = -1;
              for (i = 0; i < REMEMBERED_TO_REMOVE; i++)
                {
                  nDelta = oOdd[i].stamp - *dwLastPos;
                  if (nDelta > nMaxDelta)
                    {
                      nMaxDelta = nDelta;
                      nPos = i;
                    }
                }
              if (nPos >= 0)
                {
                  _tcscpy (oOdd[nPos].path, pszPath);
                  oOdd[nPos].stamp = *dwLastPos;
                }
            }
        }
      while (reg.FindNextValue (pszPath, &vValue));
      reg.FindClose ();
      for (i = 0; i < REMEMBERED_TO_REMOVE; i++)
        reg.DeleteKey (oOdd[i].path);
    }
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CEditPadApp object

CEditPadApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CEditPadApp initialization

BOOL CEditPadApp::
InitInstance ()
{
	CReg reg;
	if (reg.Open (HKEY_CURRENT_USER, REG_EDITPAD_SINGLE, KEY_READ|KEY_WRITE))
		{
      DWORD dwVersion;
      if (!reg.LoadNumber (NULL, _T ("Version"), &dwVersion) || dwVersion < REG_EDITPAD_VERSION)
        {
          reg.DeleteSubKeys ();
          VERIFY (reg.SaveNumber (_T ("Version"), (DWORD) REG_EDITPAD_VERSION));
	      }
    }
  reg.Close ();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

	// Initialize the common controls library
	/*INITCOMMONCONTROLSEX icex;
	icex.dwSize = sizeof( icex );
	icex.dwICC = ICC_USEREX_CLASSES;
	VERIFY( InitCommonControlsEx( &icex ) );*/

  free ((void*) m_pszHelpFilePath);
  m_pszHelpFilePath = _tcsdup (_T ("editpads.hlp"));

	// initialized OLE 2.0 libraries
	if (!AfxOleInit ())
		{
			AfxMessageBox (IDS_OLE_INIT_FAILED);
			return FALSE;
		}

#ifdef _AFXDLL
	Enable3dControls ();          // Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic ();    // Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey (_T ("EditPad\\Single"));

	LoadStdProfileSettings (16);  // Load standard INI file options (including MRU)
	CMemComboBox::LoadSettings ();
	LoadSettings ();

  // Parse command line for standard shell commands, DDE, file open
  CCommandLineInfo cmdInfo;
  ParseCommandLine (cmdInfo);

	CSplashWnd splash;
	BOOL bSplash = cmdInfo.m_bShowSplash && (m_dwFlags & EP_NO_SPLASH) == 0;
	if (!cmdInfo.m_bRunEmbedded)
	{
		switch (m_nCmdShow)
		{
			case SW_HIDE:
			case SW_SHOWMINIMIZED:
			case SW_MINIMIZE:
			case SW_SHOWMINNOACTIVE:
				bSplash = FALSE;
		}
	}
	else
	{
		//Excel 4 will start OLE servers minimized
		m_nCmdShow = SW_SHOWNORMAL;
	}
	if (bSplash)
	{
		// only show splash if not embedded
		splash.Create(NULL);
		splash.ShowWindow(SW_SHOW);
		splash.UpdateWindow();
	}

	// Initialize RichEdit control
	if (LoadLibrary(_T("RICHED32.DLL")) == NULL)
	{
		AfxMessageBox(IDS_RICHED_LOAD_FAIL, MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate *pDocTemplate;
	if (m_dwFlags & EP_ADVANCED_UI)
  	pDocTemplate = new CSingleDocTemplate (
  									 IDR_MAINFRAME,
  									 RUNTIME_CLASS (CEditPadDoc),
  									 RUNTIME_CLASS (CMainFrame),   // main SDI frame window
  									 RUNTIME_CLASS (CEditPadView));
  else
  	pDocTemplate = new CSingleDocTemplate (
  									 IDR_MAINFRAME,
  									 RUNTIME_CLASS (CEditPadDoc),
  									 RUNTIME_CLASS (CMainFrame2),   // main SDI frame window
  									 RUNTIME_CLASS (CEditPadView));
	AddDocTemplate (pDocTemplate);

	// Enable DDE Execute open
	//  EnableShellOpen();
	//  RegisterShellFileTypes(TRUE);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand (cmdInfo))
		return FALSE;

	POSITION pos = pDocTemplate->GetFirstDocPosition ();
	ASSERT (pos);
	CDocument *pDoc = pDocTemplate->GetNextDoc (pos);
	if ((m_dwFlags & EP_OPEN_LAST_DOC) && (!pDoc || pDoc->GetPathName ().IsEmpty ()))
		{
			LoadLastDoc ();
		}

	/*if (m_dwFlags & EP_ADVANCED_UI)
  	pDocTemplate = new CSingleDocTemplate (
  									 IDR_EDITPADRICHTYPE,
  									 RUNTIME_CLASS (CEditPadRichDoc),
  									 RUNTIME_CLASS (CMainFrame),   // main SDI frame window
  									 RUNTIME_CLASS (CEditPadRichView));
  else
  	pDocTemplate = new CSingleDocTemplate (
  									 IDR_EDITPADRICHTYPE,
  									 RUNTIME_CLASS (CEditPadRichDoc),
  									 RUNTIME_CLASS (CMainFrame2),   // main SDI frame window
  									 RUNTIME_CLASS (CEditPadView));
	AddDocTemplate (pDocTemplate);
	if (m_dwFlags & EP_ADVANCED_UI)
  	pDocTemplate = new CSingleDocTemplate (
  									 IDR_EDITPADBINTYPE,
  									 RUNTIME_CLASS (CEditPadBinDoc),
  									 RUNTIME_CLASS (CMainFrame),   // main SDI frame window
  									 RUNTIME_CLASS (CEditPadBinView));
  else
  	pDocTemplate = new CSingleDocTemplate (
  									 IDR_EDITPADBINTYPE,
  									 RUNTIME_CLASS (CEditPadBinDoc),
  									 RUNTIME_CLASS (CMainFrame2),   // main SDI frame window
  									 RUNTIME_CLASS (CEditPadBinView));
	AddDocTemplate (pDocTemplate);*/

	// Enable drag/drop open

⌨️ 快捷键说明

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