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

📄 wingrdoc.cpp

📁 API经典入门
💻 CPP
字号:
// wingrdoc.cpp : implementation of the CWingrepDoc class
//

#include "stdafx.h"
#include "wingrep.h"

#include "wingrdoc.h"
#include "cntritem.h"

#include "filesrch.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWingrepDoc

IMPLEMENT_DYNCREATE(CWingrepDoc, COleDocument)

BEGIN_MESSAGE_MAP(CWingrepDoc, COleDocument)
	//{{AFX_MSG_MAP(CWingrepDoc)
	ON_COMMAND(ID_GREP_SEARCH, OnGrepSearch)
	//}}AFX_MSG_MAP
	// Enable default OLE container implementation
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, COleDocument::OnUpdatePasteMenu)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, COleDocument::OnUpdatePasteLinkMenu)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleDocument::OnUpdateEditLinksMenu)
	ON_COMMAND(ID_OLE_EDIT_LINKS, COleDocument::OnEditLinks)
	ON_UPDATE_COMMAND_UI(ID_OLE_VERB_FIRST, COleDocument::OnUpdateObjectVerbMenu)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleDocument::OnUpdateObjectVerbMenu)
	ON_COMMAND(ID_OLE_EDIT_CONVERT, COleDocument::OnEditConvert)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWingrepDoc construction/destruction

CWingrepDoc::CWingrepDoc()
{
	// For most containers, using compound files is a good idea.
	EnableCompoundFile();

	// initialize the transfer protocol between 
	// the two kinds of windows used in the app.
	m_fetcTransferProtocol.cfFormat = CF_TEXT;
	m_fetcTransferProtocol.ptd = NULL;
	m_fetcTransferProtocol.dwAspect = DVASPECT_CONTENT;
	m_fetcTransferProtocol.lindex = -1;
	m_fetcTransferProtocol.tymed = TYMED_HGLOBAL;
	
	// Temporarily initialize the m_lstFiles collection
	// with a bunch of file names.
	CString S = "C:\\Test.txt";
	m_lstFiles.AddHead(S);
	S = "C:\\Test2.txt";
	m_lstFiles.AddHead(S);
	S = "C:\\Test3.txt";
	m_lstFiles.AddHead(S);
	S = "C:\\Test4.txt";
	m_lstFiles.AddHead(S);
}

CWingrepDoc::~CWingrepDoc()
{
	CString S;

	while (!m_lstFiles.IsEmpty())
	{
		S = m_lstFiles.RemoveHead();
		S.Empty();
	}	
}

BOOL CWingrepDoc::OnNewDocument()
{
	if (!COleDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CWingrepDoc serialization

void CWingrepDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}

	// Calling the base class COleDocument enables serialization
	//  of the container document's COleClientItem objects.
	COleDocument::Serialize(ar);
}

/////////////////////////////////////////////////////////////////////////////
// CWingrepDoc diagnostics

#ifdef _DEBUG
void CWingrepDoc::AssertValid() const
{
	COleDocument::AssertValid();
}

void CWingrepDoc::Dump(CDumpContext& dc) const
{
	COleDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CWingrepDoc commands
void CWingrepDoc::SearchFiles(const char* lpszSubString)
{
	CString S;
	WORD wLen = strlen(lpszSubString);
	LONG lPos;
	POSITION posCurrent = m_lstFiles.GetHeadPosition();
	POSITION posOld;
	
	while (posCurrent != NULL)
	{
		posOld = posCurrent;
		S = m_lstFiles.GetNext(posCurrent);
		TRY
		{
			// if the search was successful, then leave
			// the selection alone.
			if ( Search(S, lpszSubString, wLen, lPos) )
				continue;
		}
		CATCH( CFileException, e )
		{
			TRACE0("An exception was thrown during a file search.\n");
		}
		END_CATCH
		
		// if the search was unsuccessful, or if something
		// went wrong in the Search routine (evidenced by
		// an exception), then remove the selection.
		m_lstFiles.RemoveAt(posOld);
	}
	
	UpdateAllViews(NULL);
}

void CWingrepDoc::OnGrepSearch()
{
	const char* pString = "Test";
	SearchFiles(pString);
    /*
	CFileDialog dlg(TRUE, NULL, "C:\\*.*");
	BOOL Result;
	WORD wLen = 4;
	LONG lPos;
	
	
	
	if (dlg.DoModal() != IDOK)
		return;
	
	CString FileName = dlg.GetPathName();
	TRY
	{
		Result = Search(FileName, pString, wLen, lPos);
		if (Result)
			TRACE("The string \"Test\" was found in " + FileName + ".\n");
			
	}
	CATCH(CException, e)
	{
		TRACE0("Exception thrown during Search.\n");
	}
	END_CATCH
	*/
	
}

⌨️ 快捷键说明

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