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

📄 pages.cpp

📁 这是一个能够自动生成文档的程序
💻 CPP
字号:
// PagesManager.cpp: implementation of the CPages class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "Pages.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


CPages::CPages()
:mPageMap(100)
{

}

CPages::~CPages()
{
    ClearContent();
}

BOOL CPages::AddUserDir(LPCTSTR iDir)
{
	POSITION pos = mUserDirs.GetHeadPosition();
	while(pos != NULL)
	{
		POSITION currPos = pos;
		CString* pDir = mUserDirs.GetNext(pos);
		if(*pDir == iDir)
	        return FALSE;
	}

	//ClearContent()中删除
	CString* pNewItem = new CString(iDir);
	mUserDirs.AddTail(pNewItem);
	return TRUE;
}

BOOL CPages::AddLibDir(LPCTSTR iDir)
{
	POSITION pos = mLibDirs.GetHeadPosition();
	while(pos != NULL)
	{
		POSITION currPos = pos;
		CString* pDir = mLibDirs.GetNext(pos);
		if(*pDir == iDir)
		    return FALSE;
	}

	//ClearContent()中删除
	CString* pNewItem = new CString(iDir);
	mLibDirs.AddTail(pNewItem);
	return TRUE;
}

void CPages::DeleteUserDir(LPCTSTR iDir)
{
	POSITION pos = mUserDirs.GetHeadPosition();
	while(pos != NULL)
	{
		POSITION currPos = pos;
		CString* pDir = mUserDirs.GetNext(pos);
		if(*pDir == iDir)
		{
			delete pDir;
			mUserDirs.RemoveAt(currPos);
		}
	}
}

void CPages::DeleteLibDir(LPCTSTR iDir)
{
	POSITION pos = mLibDirs.GetHeadPosition();
	while(pos != NULL)
	{
		POSITION currPos = pos;
		CString* pDir = mLibDirs.GetNext(pos);
		if(*pDir == iDir)
		{
			delete pDir;
			mLibDirs.RemoveAt(currPos);
		}
	}
}

void CPages::ClearContent()
{
	POSITION pos = NULL;

	pos = mUserDirs.GetHeadPosition();
	while(pos != NULL)
		delete mUserDirs.GetNext(pos);

	pos = mLibDirs.GetHeadPosition();
	while(pos != NULL)
		delete mLibDirs.GetNext(pos);

    CString key;
	CPage* pPage;
    for( pos = mPageMap.GetStartPosition(); pos != NULL; )
    {
       mPageMap.GetNextAssoc(pos, key, (void*&)pPage);
	   delete pPage;
    }
}

BOOL CPages::FindFile(CString& oPathName, 
						const CString& iDirectory, 
						const CString& iFileName)
{
	oPathName.Empty();

	CString dir = iDirectory;
	if(dir.IsEmpty())
		return FALSE;

	if(dir.Right(1) != "\\")
		dir += "\\";
	    
	CFileFind finder;

	//在当前目录查找。
	BOOL found = finder.FindFile(dir + iFileName, 0);
	while(found)
    {
         found = finder.FindNextFile();
         oPathName = finder.GetFilePath();
		 return TRUE;
    }

	//如果当前目录未找到,在子目录中查找。
	found = finder.FindFile(dir + "*.*");
	while(found)
	{
		found = finder.FindNextFile();
		CString subDir = finder.GetFilePath();

		if(finder.IsDirectory())
		{
			if(!finder.IsDots())
			{
                if(FindFile(oPathName, subDir, iFileName))
				{
					return TRUE;
				}
			}
		}
	}

	ASSERT(oPathName.IsEmpty());
	return FALSE;
}

BOOL CPages::FindCodePage(CString& oPathName, 
						  LPCTSTR iFileName, 
						  BOOL iBeginOfUserDir/*=TRUE*/)
{
	CStringPtrList* pList1 = NULL;
    CStringPtrList* pList2 = NULL;

	if(iBeginOfUserDir)
	{
		pList1 = &mUserDirs;
		pList2 = &mLibDirs;
	}
	else
	{
		pList2 = &mUserDirs;
		pList1 = &mLibDirs;
	}


	POSITION pos = pList1->GetHeadPosition();
	while(pos != NULL)
	{
		CString* pDir = pList1->GetNext(pos);
		if(FindFile(oPathName, *pDir, iFileName))
			return TRUE;
	}

	pos = pList2->GetHeadPosition();
	while(pos != NULL)
	{
		CString* pDir = pList2->GetNext(pos);
		if(FindFile(oPathName, *pDir, iFileName))
			return TRUE;
	}

	ASSERT(oPathName.IsEmpty());
	return FALSE;
}

CPage* CPages::Search(LPCTSTR iPageName)
{
	 CPage* pPage = NULL;
	 mPageMap.Lookup(iPageName, (void*&)pPage);
	 return pPage;
}

CPage* CPages::AddPage(LPCTSTR iPathName)
{
    if(Search(iPathName) != NULL)
		return NULL;  //如果该代码页已存在,则返回NULL;

	//析构函数中调用ClearContent()删除
	CPage* pPage = new CPage(iPathName);
	mPageMap.SetAt(iPathName, pPage);
	return pPage;
}

⌨️ 快捷键说明

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