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

📄 editorinterface.cpp

📁 一个类似VB代码编辑器.通过一个多文档模板导出
💻 CPP
字号:
// EditorInterface.cpp: implementation of the EditorInterface class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "EditorInterface.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//CEditorDocTemplate,CEditorDocManager接口实现文件,在外部引用时可删去
//////////////////////////////////////////////////////////////////////
//CEditorDocManager实现文件
IMPLEMENT_DYNAMIC(CEditorDocManager, CDocManager)
CEditorDocManager::CEditorDocManager()
{

}

CEditorDocManager::~CEditorDocManager()
{

}
BOOL CEditorDocManager::CreateNewDocument(int doc_index)
{
	// use the doc manager to add the polyfit document
	if (m_templateList.GetCount() >= doc_index)
		{
		POSITION	pos = m_templateList.GetHeadPosition() ;
		CDocTemplate *pTemplate = NULL ;
		// iterate through the list looking for the required document type
		if (doc_index == 0)
			pTemplate = (CDocTemplate*)m_templateList.GetNext(pos) ;
		while (pos != NULL && doc_index > 0)
			{
			pTemplate = (CDocTemplate*)m_templateList.GetNext(pos) ;
			ASSERT_KINDOF(CDocTemplate, pTemplate) ;

//			if (pTemplate->m_pDocClass == pRC)
//				{
//				// found the required document type, exit loop
//				break ;
//				}
			doc_index-- ;
			}
		// creaet the document!
		pTemplate->OpenDocumentFile(NULL);
		return TRUE ;
		}

	// create the required document
	return FALSE ;
}
#ifdef _DEBUG
void CEditorDocManager::AssertValid() const
{
	CDocManager::AssertValid();
}

void CEditorDocManager::Dump(CDumpContext& dc) const
{
	CDocManager::Dump(dc);
}
#endif

int	CEditorDocManager::GetMyDocumentCount()
{
	return m_templateList.GetCount() ;
}
//以下为CEditorDocTemplate实现文件
IMPLEMENT_DYNAMIC(CEditorDocTemplate, CMultiDocTemplate)
CEditorDocTemplate::CEditorDocTemplate(HINSTANCE hInst, UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass )
: CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass)
{
	m_hInst = hInst ;
	m_ResourceID = nIDResource ;
}

CEditorDocTemplate::~CEditorDocTemplate()
{

}

void CEditorDocTemplate::LoadTemplate()
{
	// call the base class member after switching the resource to the DLL, if this is a DLL document type
	HINSTANCE	hOld ;

	hOld = AfxGetResourceHandle() ;			// save
	AfxSetResourceHandle(m_hInst) ;			// set
	CMultiDocTemplate::LoadTemplate() ;		// now get from correct resources!
	AfxSetResourceHandle(hOld) ;			// restore
}

CDocument* CEditorDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible)
{
	// switch to the correct resources and then resturn the document
	CDocument	*pDoc = NULL ;
	HINSTANCE	hOld ;

	hOld = AfxGetResourceHandle() ;			// save
	AfxSetResourceHandle(m_hInst) ;			// set
	pDoc = CMultiDocTemplate::OpenDocumentFile(lpszPathName, bMakeVisible) ;
	AfxSetResourceHandle(hOld) ;			// restore
	return pDoc ;
}

#ifdef _DEBUG
void CEditorDocTemplate::AssertValid() const
{
	CMultiDocTemplate::AssertValid();
}

void CEditorDocTemplate::Dump(CDumpContext& dc) const
{
	CMultiDocTemplate::Dump(dc);
}
#endif
//////////////////////////////////////////////////////////////////////
//Editor接口实现文件,以下必需
//////////////////////////////////////////////////////////////////////
EditorInterface::EditorInterface()
{
   EditorTemplate   = NULL ;
}

EditorInterface::~EditorInterface()
{

}
//获得可执行文件地址,并定位DLL文件地址,可自由修改路径
BOOL EditorInterface::InitialTemplate(CWinApp *APP)
{
//  CString strPath;
//  strPath = GetCommandLine() ;
//  int nLen =strPath.GetLength();
//  int nTail =-1;
//  for(int i=nLen-1;i>=0;i--)
//  {
//	  if(strPath[i] =='\\')
//	  {
//		  nTail =i;
//	      break;
//	  }
//  }
//  if(nTail<0)
//	  return false;
//  strPath =strPath.Left(nTail+1);
//  strPath +="VbsEditor.dll";	
  HINSTANCE		m_DLLhInstance ;
  m_DLLhInstance = LoadLibrary("VbsEditor.dll") ;
  if (m_DLLhInstance == NULL)
	  return false;
  DLLDocumentTemplate = (DLLINTERFACE)GetProcAddress(m_DLLhInstance, "DLLDocTemplate") ;
  EditorTemplate =DLLDocumentTemplate(APP);
  APP->AddDocTemplate(EditorTemplate);
  return true;
}
VOID EditorInterface::OpenEditorView()
{
  EditorTemplate->OpenDocumentFile(NULL);
}

⌨️ 快捷键说明

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