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

📄 benbenbrowserdoc.cpp

📁 一个多窗口的浏览器的程序benbrowse
💻 CPP
字号:
// benbenBrowserDoc.cpp : implementation of the CBenbenBrowserDoc class
//

#include "stdafx.h"
#include "benbenBrowser.h"

#include "benbenBrowserDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserDoc

IMPLEMENT_DYNCREATE(CBenbenBrowserDoc, CDocument)

BEGIN_MESSAGE_MAP(CBenbenBrowserDoc, CDocument)
	//{{AFX_MSG_MAP(CBenbenBrowserDoc)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserDoc construction/destruction

CBenbenBrowserDoc::CBenbenBrowserDoc()
{
	// TODO: add one-time construction code here
	m_iHistoryOffset = 0;
	m_arHistory.SetSize (0, 1);
}

CBenbenBrowserDoc::~CBenbenBrowserDoc()
{
	for (int i = 0; i < m_arHistory.GetSize (); i ++)
	{
		ASSERT (m_arHistory [i] != NULL);
		delete m_arHistory [i];
	}
	m_arHistory.RemoveAll();
}

BOOL CBenbenBrowserDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

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

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserDoc serialization

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

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserDoc diagnostics

#ifdef _DEBUG
void CBenbenBrowserDoc::AssertValid() const
{
	CDocument::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserDoc commandss

CHistoryObj* CBenbenBrowserDoc::AddURLToHistory (const CString& strTitle, const CString& strURL)
{
	ASSERT (m_arHistory.GetSize () <= HISTORY_LEN);
	if(strURL==""||strURL=="about:blank")	//it maybe not the url you want to browse again
		return NULL;



	for (int i = 0; i < m_arHistory.GetSize (); i ++)
	{
		CHistoryObj* pObj = m_arHistory [i];
		ASSERT (pObj != NULL);
		if (pObj->GetURL () == strURL)
		{
			m_iHistoryOffset = i;
			return pObj;
		}
	}

	//delete the forward URL
	for( i = 0; i <m_iHistoryOffset ; i ++)
	{
		delete m_arHistory [0];
		m_arHistory.RemoveAt (0);	
	}

	//make sure there only 10 items in history list
	if (m_arHistory.GetSize () == HISTORY_LEN)
	{
		delete m_arHistory [HISTORY_LEN-1];
		m_arHistory.RemoveAt (HISTORY_LEN-1);
	}
	UINT nID=GetAviliableID();
	CHistoryObj* pObj = new CHistoryObj (strTitle, strURL,nID);
	m_arHistory.InsertAt (0, pObj);

	m_iHistoryOffset = 0;//the new item is always inserted at positon 0 ,so the current position is zeor
	return pObj;
}
//****************************************************************************************
void CBenbenBrowserDoc::GetBackList (_T_HistotyList& lst) const
{
	lst.RemoveAll ();
	for (int i = m_iHistoryOffset + 1; i < m_arHistory.GetSize () ; i ++)
	{
		lst.AddTail (m_arHistory [i]);
	}
}
//****************************************************************************************
void CBenbenBrowserDoc::GetFrwdList (_T_HistotyList& lst) const
{
	lst.RemoveAll ();
	for (int i = m_iHistoryOffset - 1; i >= 0; i --)
	{
		ASSERT (i < m_arHistory.GetSize ());
		lst.AddTail (m_arHistory [i]);
	}
}
//****************************************************************************************
CHistoryObj* CBenbenBrowserDoc::Go(UINT uiCmd)
{
	for (int i = 0; i < m_arHistory.GetSize (); i ++)
	{
		CHistoryObj* pObj = m_arHistory [i];
		ASSERT (pObj != NULL);

		if (pObj->GetCommand () == uiCmd)
		{
			m_iHistoryOffset = i;
			return pObj;
		}
	}

	return NULL;
}


int CBenbenBrowserDoc::GetAviliableID()
{
	BOOL nID[10]={0};
	for(int i=0;i< m_arHistory.GetSize ();i++)
	{
		ASSERT(m_arHistory[i]->GetCommand()-FIRST_HISTORY_COMMAND<10);
		nID[m_arHistory[i]->GetCommand()-FIRST_HISTORY_COMMAND]=1;
	}
	for(i=0;i<10;i++)
	{
		if(nID[i]==0)
			return i+FIRST_HISTORY_COMMAND;
	}
	return 0;
}

⌨️ 快捷键说明

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