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

📄 benbenbrowserview.cpp

📁 一个多窗口的浏览器的程序benbrowse
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// benbenBrowserView.cpp : implementation of the CBenbenBrowserView class
//

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

#include "benbenBrowserDoc.h"
#include "benbenBrowserView.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "ExDisp.h"

#include <Mshtmdid.h>
#include  "tlogstg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserView

IMPLEMENT_DYNCREATE(CBenbenBrowserView, CHtmlViewBen)

BEGIN_MESSAGE_MAP(CBenbenBrowserView, CHtmlViewBen)
	//{{AFX_MSG_MAP(CBenbenBrowserView)
	ON_COMMAND(ID_GO_BACK, OnGoBack)
	ON_COMMAND(ID_GO_FORWARD, OnGoForward)
	ON_COMMAND(ID_GO_SEARCH_THE_WEB, OnGoSearchTheWeb)
	ON_COMMAND(ID_GO_START_PAGE, OnGoStartPage)
	ON_COMMAND(ID_VIEW_FONTS_LARGE, OnViewFontsLarge)
	ON_COMMAND(ID_VIEW_FONTS_LARGEST, OnViewFontsLargest)
	ON_COMMAND(ID_VIEW_FONTS_MEDIUM, OnViewFontsMedium)
	ON_COMMAND(ID_VIEW_FONTS_SMALL, OnViewFontsSmall)
	ON_COMMAND(ID_VIEW_FONTS_SMALLEST, OnViewFontsSmallest)
	ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
	ON_COMMAND(ID_VIEW_STOP, OnViewStop)
	ON_COMMAND(ID_SELECTALL_EDIT, OnSelectallEdit)
	ON_UPDATE_COMMAND_UI(ID_SELECTALL_EDIT, OnUpdateSelectallEdit)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
	ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
	ON_COMMAND(ID_ADDTOFAVORITES_FAVORITE, OnAddtofavoritesFavorite)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_PROPERTIES_FILE, OnPropertiesFile)
	ON_UPDATE_COMMAND_UI(ID_GO_BACK, OnUpdateGoBack)
	ON_UPDATE_COMMAND_UI(ID_GO_FORWARD, OnUpdateGoForward)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
	ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_SETUP, OnFilePrintSetup)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_LARGE, OnUpdateViewFontsLarge)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_LARGEST, OnUpdateViewFontsLargest)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_MEDIUM, OnUpdateViewFontsMedium)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_SMALL, OnUpdateViewFontsSmall)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_SMALLEST, OnUpdateViewFontsSmallest)
	ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
	ON_COMMAND(ID_EDIT_CUT, OnEditCut)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
	ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CHtmlViewBen::OnFilePrint)
	END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserView construction/destruction

CBenbenBrowserView::CBenbenBrowserView()
{
	// TODO: add construction code here
	m_beActive=FALSE;
	m_bePopUpWin=FALSE;
	m_bNavigateForward=FALSE;
	m_bNavigateBack=FALSE;
	m_progress=-1;
	m_beInUse=TRUE;
}

CBenbenBrowserView::~CBenbenBrowserView()
{
}

BOOL CBenbenBrowserView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CHtmlViewBen::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserView drawing

void CBenbenBrowserView::OnDraw(CDC* pDC)
{
	CBenbenBrowserDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

void CBenbenBrowserView::OnInitialUpdate()
{
	CHtmlViewBen::OnInitialUpdate();

	// TODO: This code navigates to a popular spot on the web.
	//  change the code to go where you'd like.
	//Navigate2(_T("about:blank"),NULL,NULL);
	//GoHome();
}

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserView printing


/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserView diagnostics

#ifdef _DEBUG
void CBenbenBrowserView::AssertValid() const
{
	CHtmlViewBen::AssertValid();
}

void CBenbenBrowserView::Dump(CDumpContext& dc) const
{
	CHtmlViewBen::Dump(dc);
}

CBenbenBrowserDoc* CBenbenBrowserView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBenbenBrowserDoc)));
	return (CBenbenBrowserDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CBenbenBrowserView message handlers

void CBenbenBrowserView::OnGoBack() 
{
	// TODO: Add your command handler code here
	try
	{
		if(IsIEHistoryAviliable())
			GoBack();
		else
		{
			CBenbenBrowserDoc* pDoc = GetDocument();
			ASSERT_VALID(pDoc);
			CHistoryObj* pHistoryObj = pDoc->GoBack ();
			if(pHistoryObj)
				Navigate(pHistoryObj->GetURL(),NULL,NULL);
		}
	}
	catch(...)
	{
	}
//	GoBack();
}

void CBenbenBrowserView::OnGoForward() 
{
	// TODO: Add your command handler code here
	try
	{
		if(IsIEHistoryAviliable())
			GoForward();
		else
		{
			CBenbenBrowserDoc* pDoc = GetDocument();
			ASSERT_VALID(pDoc);
			
			CHistoryObj* pHistoryObj = pDoc->GoForward ();
			if(pHistoryObj)
				Navigate(pHistoryObj->GetURL(),NULL,NULL);
		}
	}
	catch(...)
	{
	}
//	GoForward();
}

void CBenbenBrowserView::OnGoSearchTheWeb() 
{
	// TODO: Add your command handler code here
	GoSearch();
}

void CBenbenBrowserView::OnGoStartPage() 
{
	// TODO: Add your command handler code here
	GoHome();
}


void CBenbenBrowserView::OnViewFontsLargest() 
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(4l);
	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}

void CBenbenBrowserView::OnViewFontsLarge() 
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(3l);
	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}

void CBenbenBrowserView::OnViewFontsMedium() 
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(2l);
	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);
}

void CBenbenBrowserView::OnViewFontsSmall() 
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(1l);
	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);	
}

void CBenbenBrowserView::OnViewFontsSmallest() 
{
	// TODO: Add your command handler code here
	COleVariant vaZoomFactor(0l);
	ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
		   &vaZoomFactor, NULL);		
}

void CBenbenBrowserView::OnViewRefresh() 
{
	// TODO: Add your command handler code here
	Refresh();
}

void CBenbenBrowserView::OnViewStop() 
{
	// TODO: Add your command handler code here
	Stop();
}



void CBenbenBrowserView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel) 
{
	// TODO: Add your specialized code here and/or call the base class
	CHtmlViewBen::OnBeforeNavigate2(lpszURL, nFlags,lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel);
	try
	{	
		CString URL(lpszURL);
		if(URL=="about:blank")//to know whether this view is used or not
			SetbeInUse(FALSE);
		else
			SetbeInUse(TRUE);

		CMainFrame *pMainFrm=(CMainFrame *)AfxGetApp()->m_pMainWnd;
		if(pMainFrm->m_lockURLlist.Find(lpszURL)!=NULL)
		{
			*pbCancel=TRUE;
			m_bePopUpWin=TRUE;
		}
		else 
		{
			if(m_beActive)
			{
				pMainFrm->PlayAnimate();
				pMainFrm->SetAddressComText(lpszURL);
			}
			pMainFrm->SetViewNames(lpszURL,this);
		}
	//	m_wndBrowser.SetFocus(); //you will never believe that I spent more than 2 weeks to remove this line,enjoy it
		if(m_bePopUpWin)
		{
			//I spent about two weeks on this line;
			//first i try SendMessage(WM_CLOSE),but it cause the applicaton collapse
			PostMessage(WM_COMMAND,ID_FILE_CLOSE,0);
		}
	}
	catch(...)
	{
	}
}

void CBenbenBrowserView::OnSelectallEdit() 
{
	// TODO: Add your command handler code here
	ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
}

void CBenbenBrowserView::OnUpdateSelectallEdit(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
}


void CBenbenBrowserView::OnEditCopy() 
{
	// TODO: Add your command handler code here
	ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); 
}

void CBenbenBrowserView::OnUpdateEditCopy(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here

}

void CBenbenBrowserView::OnFileSaveAs() 
{
	// TODO: Add your command handler code here
	ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT , NULL, NULL); 
}

void CBenbenBrowserView::OnUpdateFileSaveAs(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}
void CBenbenBrowserView::OnPropertiesFile() 
{
	// TODO: Add your command handler code here
	ExecWB(OLECMDID_PROPERTIES, OLECMDEXECOPT_DODEFAULT , NULL, NULL); 
}


void CBenbenBrowserView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel) 
{
	// TODO: Add your specialized code here and/or call the base class
	try
	{
		if(*Cancel==0)
		{
			
			CMainFrame * mainframe=(CMainFrame *)AfxGetApp()->m_pMainWnd;
			
			CBenbenBrowserView *view=(CBenbenBrowserView *)mainframe->NewHtmlView(0);
			if(view)
			{
				*ppDisp=view->GetApplication();
			}
			
		}
		else
			*Cancel=1;
	}
	catch(...)
	{
	}
	CHtmlViewBen::OnNewWindow2(ppDisp, Cancel);
}

void CBenbenBrowserView::OnAddtofavoritesFavorite() 
{
	// TODO: Add your command handler code here
	try
	{
		IShellUIHelper* pShell = NULL;
		HRESULT hr = CoCreateInstance(CLSID_ShellUIHelper, NULL, CLSCTX_SERVER,
			IID_IShellUIHelper, (void**)&pShell);
		if (hr == S_OK)
		{
			CString urltitle=GetLocationName();
			COleVariant vtTitle=urltitle;//("Miasdgasdgasdcrosoft");
			CString sURL=GetLocationURL();
			BSTR url=sURL.AllocSysString();
			pShell->AddFavorite(url, &vtTitle);
			SysFreeString(url);
			
			pShell->Release();
			
			CMainFrame *pframe=(CMainFrame *)AfxGetApp()->m_pMainWnd;
			pframe->RefreshFavoriteMenu();
		}
	}
	catch(...)
	{
	}
}


void CBenbenBrowserView::OnFileOpen() 
{
	// TODO: Add your command handler code here
	CString str;
	str="HTML Files(*.htm,*.html)|*.htm;*.html|Text Files(*.txt)|*.txt|GIF Files(*.gif)|*.gif|JPEG Files(*.jpg;*.jpeg)|*.jpg;*.jpeg|AU Files(*.au)|*.au|AIFF Files(*.aif;*.aiff)|*.aif;*.aiff|XBM Files(*.xbm)|*.xbm|All Files(*.*)|*.*||";
	CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, str);
	if(fileDlg.DoModal() == IDOK)
		Navigate2(fileDlg.GetPathName(),navNoReadFromCache, NULL);
}

void CBenbenBrowserView::OnUpdateGoBack(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	try
	{
		if(IsIEHistoryAviliable())
			pCmdUI->Enable (m_bNavigateBack);
		else
		{
			CBenbenBrowserDoc* pDoc = GetDocument();
			ASSERT_VALID(pDoc);
			pCmdUI->Enable (pDoc->IsBackAvailable ());
		}
	}
	catch(...)
	{
	}
}

void CBenbenBrowserView::OnUpdateGoForward(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	try
	{
		if(IsIEHistoryAviliable())
			pCmdUI->Enable(m_bNavigateForward);
		else
		{
			CBenbenBrowserDoc* pDoc = GetDocument();
			ASSERT_VALID(pDoc);
			pCmdUI->Enable (pDoc->IsFrwdAvailable());
		}
	}
	catch(...)
	{
	}
}

⌨️ 快捷键说明

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