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

📄 cedtapp.cpp

📁 Crimson编辑器的英文版,完成从韩文版变成英文版的移植,并且附带可执行文件和注册表文件,无需原先的安装包,是改写编辑器的最理想选择.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	// Initialize common control library for XP Look
	InitCommonControls();

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

	// check multi-byte language
	m_bDoubleByteCharacterSet = FALSE;
	CheckDoubleByteCharacterSet();

	// load user configuration
	if( ! LoadUserConfiguration() ) {
		AfxMessageBox(IDS_ERR_CONFIG_FILE, MB_OK | MB_ICONEXCLAMATION);
		SetDefaultConfiguration();
		SaveUserConfiguration();
	}

	// load color settings
	if( ! LoadColorSettings() ) {
		SetDefaultColorSettings();
		SaveColorSettings();
	}

	// load FTP account information
	LoadFtpAccountInfo(m_szInstallDirectory + "\\cedt.ftp");

	// load command & macro
	LoadUserCommands(m_szInstallDirectory + "\\cedt.cmd");
	LoadMacroBuffers(m_szInstallDirectory + "\\cedt.mac");

//	SetRegistryKey(STRING_COMPANYNAME); // Change the registry key under which our settings are stored.
	LoadStdProfileSettings(8);  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.
	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_CEDTTYPE,
		RUNTIME_CLASS(CCedtDoc),
		RUNTIME_CLASS(CChildFrame),
		RUNTIME_CLASS(CCedtView));
	AddDocTemplate(pDocTemplate);

	// Create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if ( ! pMainFrame->LoadFrame(IDR_MAINFRAME) ) return FALSE;
	m_pMainWnd = pMainFrame;

	// save first instance window handle 
	if( ! hFirstWindow ) hFirstWindow = pMainFrame->m_hWnd;

	// Load cursor resources
	m_hCursorArrow = LoadStandardCursor(IDC_ARROW);
	m_hCursorIBeam = LoadStandardCursor(IDC_IBEAM);
	m_hCursorCross = LoadStandardCursor(IDC_CROSS);
	m_hCursorRightArrow = LoadCursor(IDC_RIGHT_ARROW);
	m_hCursorArrowMacro = LoadCursor(IDC_ARROW_MACRO);
	m_hCursorIBeamMacro = LoadCursor(IDC_IBEAM_MACRO);

	// Accept files from drag and drop
	pMainFrame->DragAcceptFiles(TRUE);

	// File window initialization
	CFileWindow * pFileWindow = (CFileWindow *)pMainFrame->GetFileWindow();

	pFileWindow->InitLocalDriveList(NULL);
	pFileWindow->InitFileFilterList( GetComposedFileFilter(), m_nFilterIndexPannel, CallbackFilterIndexPannel );
	pFileWindow->InitProjectWorkspace();

	// File window browsing directory & current working directory
	if( m_szInitialWorkingDirectory.GetLength() ) {
		pFileWindow->SetBrowsingDirectory( m_szInitialWorkingDirectory );
		// redundant code - SetBrowsingDirectory() will set current working directory
		::SetCurrentDirectory( m_szInitialWorkingDirectory );
	} else {
		LoadBrowsingDirectory(REGKEY_BROWSING_DIR);
		// current working directory might differ from browsing directory
		LoadWorkingDirectory(REGKEY_WORKING_DIR);
	}

	// Load prev workspace pathname
	m_szPrevWorkspacePathName = "";
	LoadWorkspaceFilePath(REGKEY_LAST_WORKSPACE);

	// Load window placement & bar state
	pMainFrame->LoadWindowPlacement(REGKEY_WINDOW_PLACEMENT);
	pMainFrame->LoadBarState(REGKEY_BAR_STATE);

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(SW_SHOW);
	pMainFrame->UpdateWindow();

	// Reload last working files
	if( m_bReloadWorkingFilesOnStartup && m_bFirstInstance ) ReloadLastWorkingFiles();

	// Parse command line for standard shell commands, DDE, file open
	CCmdLine cmdLine(__argc, __argv);
	ProcessShellCommand(cmdLine);

	// Create new document on start up
	if( m_bCreateNewDocumentOnStartup ) CreateNewDocumentIfNothingLoaded();

	return TRUE;
}

int CCedtApp::ExitInstance() 
{
	// User configuration is saved when mainframe is closed and whenever there is a change
	// SaveUserConfiguration();

	// Uninitialize HtmlHelp if it was initialized
	if( m_bHtmlHelpInitialized ) {
		::HtmlHelp(NULL, NULL, HH_UNINITIALIZE, (DWORD)&m_dwHtmlHelpCookie);
		m_bHtmlHelpInitialized = FALSE;
	}

	return CWinApp::ExitInstance();
}


/////////////////////////////////////////////////////////////////////////////
// CCedtApp operations

BOOL CCedtApp::CheckDoubleByteCharacterSet()
{
	if( GetSystemMetrics(SM_DBCSENABLED) ) m_bDoubleByteCharacterSet = TRUE;
	else m_bDoubleByteCharacterSet = FALSE;
	return TRUE;
}

BOOL CCedtApp::ProcessShellCommand(CCmdLine & rCmdLine)
{
	CString szOption, szDirectory; 
	BOOL bNoCreate = FALSE; INT nLineNumber = 1;

	if( rCmdLine.HasSwitch("NC", szOption) ) bNoCreate = TRUE;
	if( rCmdLine.HasSwitch("L" , szOption) ) nLineNumber = atoi(szOption);
	if( rCmdLine.HasSwitch("D" , szOption) ) szDirectory = ChopDirectory(szOption);

	CString szPrefix = ChopDirectory(m_szLoadingDirectory);
	if( szDirectory.GetLength() ) szPrefix = szDirectory;

	for(INT i = 0; i < rCmdLine.GetArgumentCount(); i++) {
		CString szArgument = rCmdLine.GetArgument(i);

		// check if it is absolute path without drive name, then append drive name
		if( szArgument[0] == '\\' && szArgument[1] != '\\' ) szArgument = szPrefix.Mid(0, 2) + szArgument;

		BOOL bAbsolute = FALSE, bWildCard = FALSE;
		if( szArgument.Mid(0, 2) == "\\\\" || szArgument.Mid(1, 2) == ":\\" ) bAbsolute = TRUE;
		if( szArgument.Find('*') >= 0 || szArgument.Find('?') >= 0 ) bWildCard = TRUE;

		CString szPathName = szArgument; 
		if( ! bAbsolute ) szPathName = szPrefix + "\\" + szArgument;

		CStringArray arrPathName; 
		BOOL bFound = FindAllFilePath(arrPathName, szPathName);

		if( bFound ) {
			for(INT j = 0; j < arrPathName.GetSize(); j++) {
				OpenDocumentFile( GetLongPathName(arrPathName[j]), nLineNumber, NULL );
			}
		} else if( ! bWildCard ) {
			if( ! bNoCreate ) {
				BOOL bCreated = TouchFile( szPathName ); // create a file
				OpenDocumentFile( GetLongPathName(szPathName), nLineNumber, NULL );
			} else { // if /NC is specified
			//	CString szMessage; szMessage.Format(IDS_FILE_NOT_FOUND_ERROR, szPathName);
			//	AfxMessageBox(szMessage, MB_OK | MB_ICONEXCLAMATION);
			}
		}
	}

	return TRUE;
}

void CCedtApp::OnAnotherInstance()
{
/*	CMainFrame * pMainFrame = (CMainFrame *)AfxGetMainWnd(); if( ! pMainFrame ) return;
	if( pMainFrame->IsIconic() ) pMainFrame->ShowWindow( SW_RESTORE );
	else pMainFrame->ShowWindow( SW_SHOW );

//	pMainFrame->BringWindowToTop();
	if( pMainFrame->SetForegroundWindow() ) {
		pMainFrame->ShowOwnedPopups( TRUE );
	} else {
	//	pMainFrame->ShowWindow( SW_MINIMIZE );
	//	pMainFrame->ShowWindow( SW_RESTORE );
	} */

	TCHAR szBuffer[4096]; CStringArray arrCmdLine;

	CMutex mutex(FALSE, MUTEX_NAME_CMDLINE);
	CSingleLock lock( & mutex ); lock.Lock();

	ifstream fin(m_szInstallDirectory + "\\cmdline.txt", ios::in | ios::nocreate);
	while( fin.good() ) {
		fin.getline(szBuffer, 4096);
		if( strlen(szBuffer) ) arrCmdLine.Add(szBuffer);
	}
	fin.close();

	ofstream fout(m_szInstallDirectory + "\\cmdline.txt", ios::out );
	fout.close();

	lock.Unlock();

	for(INT i = 0; i < arrCmdLine.GetSize(); i++) {
		CCmdLine cmdLine( arrCmdLine[i] );
		ProcessShellCommand(cmdLine);
	}
}

POSITION CCedtApp::GetFirstDocPosition()
{
	POSITION posTemplate = GetFirstDocTemplatePosition();
	CDocTemplate * pTemplate = GetNextDocTemplate( posTemplate );
	return pTemplate->GetFirstDocPosition();
}

CDocument * CCedtApp::GetNextDoc(POSITION & rPos)
{
	POSITION posTemplate = GetFirstDocTemplatePosition();
	CDocTemplate * pTemplate = GetNextDocTemplate( posTemplate );
	return pTemplate->GetNextDoc( rPos );
}

INT CCedtApp::GetDocumentCount()
{
	INT nCount = 0; POSITION posDoc = GetFirstDocPosition();
	while( posDoc ) { 
		CCedtDoc * pDoc = (CCedtDoc *)GetNextDoc( posDoc ); 
		nCount++; 
	}
	return nCount;
}

INT CCedtApp::GetViewCount()
{
	INT nCount = 0; POSITION posDoc = GetFirstDocPosition();
	while( posDoc ) {
		CCedtDoc * pDoc = (CCedtDoc *)GetNextDoc( posDoc ); 
		nCount += pDoc->GetViewCount();
	}
	return nCount;
}

/////////////////////////////////////////////////////////////////////////////
// CCedtApp message handlers
BOOL CCedtApp::PreTranslateMessage(MSG* pMsg) 
{
	switch( pMsg->message ) {
	case WM_ANOTHER_INSTANCE:
		OnAnotherInstance();
		return TRUE;
	}
	
	return CWinApp::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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