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

📄 myieview.cpp

📁 myie的源程序是用VC++写自已可以扩搌使用
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// MyIEView.cpp : implementation of the CMyIEView class
//

#include "stdafx.h"
#include "MyIE.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include <wininet.h>

#include <Mshtmdid.h>
//#include "MyIEDoc.h"
#include "MyIEView.h"
#include "mshtml.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyIEView

IMPLEMENT_DYNCREATE(CMyIEView, CFixedHtmlView)

BEGIN_MESSAGE_MAP(CMyIEView, CFixedHtmlView)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_COMMAND(ID_EDIT_CUT, OnEditCut)
	ON_COMMAND(ID_EDIT_FIND, OnEditFind)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
	ON_COMMAND(ID_OPTIONS_LOADIMAGE, OnOptionsLoadimage)
	ON_UPDATE_COMMAND_UI(ID_OPTIONS_LOADIMAGE, OnUpdateOptions)
	ON_COMMAND(ID_OPTIONS_ALLOWSCRIPTS, OnOptionsAllowscripts)
	ON_COMMAND(ID_OPTIONS_LOADSOUNDS, OnOptionsLoadsounds)
	ON_COMMAND(ID_OPTIONS_LOADVIDEOS, OnOptionsLoadvideos)
	ON_COMMAND(ID_OPTIONS_USE_WEBP, OnOptionsUseWebp)
	ON_UPDATE_COMMAND_UI(ID_OPTIONS_USE_WEBP, OnUpdateOptionsUseWebp)
	ON_COMMAND(ID_OPTIONS_ALLOWACTIVEX, OnOptionsAllowactivex)
	ON_COMMAND(ID_OPTIONS_ALLOWJAVAAPPLET, OnOptionsAllowjavaapplet)
	ON_UPDATE_COMMAND_UI(ID_GO_BACK, OnUpdateGoBack)
	ON_UPDATE_COMMAND_UI(ID_GO_FORWARD, OnUpdateGoForward)
//	ON_WM_ERASEBKGND()
	ON_UPDATE_COMMAND_UI(ID_OPTIONS_ALLOWSCRIPTS, OnUpdateOptions)
	ON_UPDATE_COMMAND_UI(ID_OPTIONS_LOADSOUNDS, OnUpdateOptions)
	ON_UPDATE_COMMAND_UI(ID_OPTIONS_LOADVIDEOS, OnUpdateOptions)
	ON_UPDATE_COMMAND_UI(ID_OPTIONS_ALLOWACTIVEX, OnUpdateOptions)
	ON_UPDATE_COMMAND_UI(ID_OPTIONS_ALLOWJAVAAPPLET, OnUpdateOptions)
	ON_WM_SIZE()
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_LARGEST, OnUpdateViewFonts)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_LARGE, OnUpdateViewFonts)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_MEDIUM, OnUpdateViewFonts)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_SMALL, OnUpdateViewFonts)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FONTS_SMALLEST, OnUpdateViewFonts)
	//{{AFX_MSG_MAP(CMyIEView)
	ON_COMMAND(ID_EDIT_EDIT, OnEditEdit)
	ON_WM_PARENTNOTIFY()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	// Standard printing commands
	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_STOP, OnViewStop)
	ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
	/*ON_COMMAND(ID_HELP_WEB_TUTORIAL, OnHelpWebTutorial)
	ON_COMMAND(ID_HELP_ONLINE_SUPPORT, OnHelpOnlineSupport)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_FREE_STUFF, OnHelpMicrosoftOnTheWebFreeStuff)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_FREQUENTLY_ASKED_QUESTIONS, OnHelpMicrosoftOnTheWebFrequentlyAskedQuestions)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_GET_FASTER_INTERNET_ACCESS, OnHelpMicrosoftOnTheWebGetFasterInternetAccess)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_MICROSOFT_HOME_PAGE, OnHelpMicrosoftOnTheWebMicrosoftHomePage)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_SEARCH_THE_WEB, OnHelpMicrosoftOnTheWebSearchTheWeb)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_SEND_FEEDBACK, OnHelpMicrosoftOnTheWebSendFeedback)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_INTERNET_START_PAGE, OnHelpMicrosoftOnTheWebInternetStartPage)
	ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_BEST_OF_THE_WEB, OnHelpMicrosoftOnTheWebBestOfTheWeb) */
	ON_COMMAND(ID_VIEW_FONTS_LARGEST, OnViewFontsLargest)
	ON_COMMAND(ID_VIEW_FONTS_LARGE, OnViewFontsLarge)
	ON_COMMAND(ID_VIEW_FONTS_MEDIUM, OnViewFontsMedium)
	ON_COMMAND(ID_VIEW_FONTS_SMALL, OnViewFontsSmall)
	ON_COMMAND(ID_VIEW_FONTS_SMALLEST, OnViewFontsSmallest)
//	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_TOOLS_AUTOSCROLL_AUTOSCROLLINGAFTERDOWNLOADING, OnToolsAutoscrollAutoscrollingafterdownloading)
	ON_UPDATE_COMMAND_UI(ID_TOOLS_AUTOSCROLL_AUTOSCROLLINGAFTERDOWNLOADING, OnUpdateToolsAutoscrollAutoscrollingafterdownloading)
	ON_COMMAND(ID_TOOLS_AUTOSCROLL_FAST, OnToolsAutoscrollFast)
	ON_UPDATE_COMMAND_UI(ID_TOOLS_AUTOSCROLL_FAST, OnUpdateToolsAutoscrollFast)
	ON_COMMAND(ID_TOOLS_AUTOSCROLL_MEDIUM, OnToolsAutoscrollMedium)
	ON_UPDATE_COMMAND_UI(ID_TOOLS_AUTOSCROLL_MEDIUM, OnUpdateToolsAutoscrollMedium)
	ON_COMMAND(ID_TOOLS_AUTOSCROLL_SLOW, OnToolsAutoscrollSlow)
	ON_UPDATE_COMMAND_UI(ID_TOOLS_AUTOSCROLL_SLOW, OnUpdateToolsAutoscrollSlow)
	ON_COMMAND(ID_TOOLS_AUTOSCROLL_USEAUTOSCROLLING, OnToolsAutoscrollUseautoscrolling)
	ON_UPDATE_COMMAND_UI(ID_TOOLS_AUTOSCROLL_USEAUTOSCROLLING, OnUpdateToolsAutoscrollUseautoscrolling)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyIEView construction/destruction

CMyIEView::CMyIEView()
{
	// TODO: add construction code here
	IsPopUp = FALSE;
	dwProperty = 0;
	
	m_bEnWebProxy = FALSE;

	IsActive = FALSE;

	m_back= FALSE;
	m_forward = FALSE;

	m_nProgress = -1;

	m_IsNewPopup = FALSE;

	bDelayAdd = TRUE;

	m_nFontSize = nDefFontSize; //4, smallest, 3, small, 2, medium, 1, large, 0, largest

	//load internet setting
	HKEY            hKey;
	TCHAR           sz[MAX_PATH];
	DWORD           dwSize = MAX_PATH;

	if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Internet Explorer\\Main"), &hKey) != ERROR_SUCCESS)
	{
		TRACE0("Main setting not found\n");
		return ;
	}
	dwSize = sizeof(sz);
	RegQueryValueEx(hKey, _T("Display Inline Images"), NULL, NULL, (LPBYTE)sz, &dwSize);
	if(strcmp(sz, "yes")==0)
		dwProperty |=DLCTL_DLIMAGES;
	
	dwSize = MAX_PATH;
	RegQueryValueEx(hKey, _T("Display Inline Videos"), NULL, NULL, (LPBYTE)sz, &dwSize);
	if(strcmp(sz, "yes")==0)
		dwProperty |=DLCTL_VIDEOS;

	dwSize = MAX_PATH;
	RegQueryValueEx(hKey, _T("Play_Background_Sounds"), NULL, NULL, (LPBYTE)sz, &dwSize);
	if(strcmp(sz, "yes")==0)
		dwProperty |=DLCTL_BGSOUNDS;

	RegCloseKey(hKey);

	if(AfxGetApp()->GetProfileInt("Settings", "NoJava", 0))
		dwProperty |= DLCTL_NO_JAVA;

	if(AfxGetApp()->GetProfileInt("Settings", "NoActivex", 0))
		dwProperty |= DLCTL_NO_RUNACTIVEXCTLS;

	if(AfxGetApp()->GetProfileInt("Settings", "NoScript", 0))
		dwProperty |= DLCTL_NO_SCRIPTS;

	//keep silent???
	if(bSilent)
		dwProperty |= DLCTL_SILENT;

	m_bForceRefresh = FALSE;

	m_tLastClick.LowPart = 0;

	m_bFirst = TRUE;

	m_nSrSpeed = 1; //1-slow, 2-medium, 3-fast
	m_bScrollAfterDL = TRUE;
	m_bUseAutoScroll = FALSE;

	m_nScrollTimer = 0;

	oldIcon = -1;
}

CMyIEView::~CMyIEView()
{
	if(m_nScrollTimer)
		KillTimer(m_nScrollTimer);
}

BOOL CMyIEView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	//cs.style |= WS_CLIPCHILDREN;

    cs.lpszClass = AfxRegisterWndClass(
       CS_DBLCLKS,                       // if you need double-clicks
       NULL,                             // no cursor (use default)
       NULL,                             // no background brush
       NULL); // app icon
    ASSERT(cs.lpszClass);

	return CFixedHtmlView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyIEView drawing


void CMyIEView::OnInitialUpdate(int nOpenType, LPCSTR strUrl)
{

	m_bFirst = TRUE;
	CFixedHtmlView::OnInitialUpdate();
	if (nOpenType == 0)
	{
		m_lpszUrl = "about:blank";
		Navigate2(m_lpszUrl, 0, NULL);
	}
	else if (nOpenType == 2)
		if(strUrl!=NULL && strUrl!="")
		{
			Navigate2(strUrl, 0, NULL);
			m_lpszUrl = strUrl;
		}
		else
		{
			m_lpszUrl = "about:blank";
			Navigate2(m_lpszUrl, 0, NULL);
		}
	else
		GoHome();

	//nOpenType = 1;

	m_strWebProxy = ((CMainFrame*)(AfxGetApp()->m_pMainWnd))->m_strDefaultWebProxy;


	// TODO: This code navigates to a popular spot on the web.
	//  change the code to go where you'd like.
	//Navigate2(_T("http://www.microsoft.com/visualc/"),NULL,NULL);
}

/////////////////////////////////////////////////////////////////////////////
// CMyIEView printing


/////////////////////////////////////////////////////////////////////////////
// CMyIEView diagnostics

#ifdef _DEBUG
void CMyIEView::AssertValid() const
{
	CFixedHtmlView::AssertValid();
}

void CMyIEView::Dump(CDumpContext& dc) const
{
	CFixedHtmlView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CMyIEView message handlers
void CMyIEView::OnTitleChange(LPCTSTR lpszText)
{
	// this will change the main frame's title bar
//	if (m_pDocument != NULL )
//		m_pDocument->SetTitle(lpszText);

	CChildFrame* tcf = ((CChildFrame*)GetParentFrame());
	if(tcf!=NULL)
	{
		if(tcf->m_strStickName != "")
		{
			tcf->SetWindowText(tcf->m_strStickName);
		}
		else
		{
			tcf->SetWindowText(lpszText);
		}
		tcf->m_Title = lpszText;
	}

	CString url = GetLocationURL();
	if(!IsPopUp && EnablePopupFilter && m_IsNewPopup)
	{
		if(((CMainFrame*)pMainFrame)->m_astrPopup.Find(url)!=NULL || PopFilterStar(url))
		{
			IsPopUp = TRUE;
			m_strPossibleURL = url;
		}
	}
	if(IsPopUp && m_IsNewPopup)
	{	//is the popup is in a frame or top window
		CString url2 = url.Right(m_strPossibleURL.GetLength()+13);
		if(url2 == "navcancl.htm#" + m_strPossibleURL /*for IE 5*/|| url == "about:NavigationCanceled" /*for IE4*/ || url==m_strPossibleURL)
		{
		//	CChildFrame* tcf = (CChildFrame*)GetParentFrame();
			if(tcf!=NULL) 
				tcf->SendMessage(WM_CLOSE);

			IsPopUp = FALSE;
			return;
		}
		else
			tcf->ShowWindow(SW_SHOW);

	}
	else
		tcf->ShowWindow(SW_SHOW);

/*	if(IsActive && tcf!=NULL )
	{
		//set focus
		tcf->SetFocus();
		SetFocus();
		m_wndBrowser.SetFocus();
	}
*/
	IsPopUp = FALSE;

	if(url!="" && !url.IsEmpty())
		m_lpszUrl = url;

	if(pMainFrame!=NULL)
	{
		//set the new title of tab
		if(tcf->m_strStickName=="")
		{
			int nTabID = ((CMainFrame*)pMainFrame)->FindTab((CChildFrame*)GetParentFrame());
			((CMainFrame*)pMainFrame)->SetTabTitle( (char*)lpszText, nTabID );
		}
		if(IsActive && !url.IsEmpty() && url!="")
		{
			((CMainFrame*)pMainFrame)->SetAddress(url);
		
		}

		//update tab bar
		if(!((CMainFrame*)pMainFrame)->m_bAutoTab)
			pMainFrame->PostMessage(WM_UPDATE_TAB);
	}
}

void CMyIEView::OnDocumentComplete(LPCTSTR lpszUrl)
{
	// make sure the main frame has the new URL.  This call also stops the animation

	CString strUrl = GetLocationURL();
	if((strUrl == "" || strUrl.IsEmpty()) && lpszUrl!=NULL)
		strUrl = lpszUrl;

	if(IsActive && pMainFrame!=NULL)
	{
		//((CMainFrame*)((CChildFrame*)GetParentFrame()->GetParentFrame()))->SetAddress(strUrl);
		((CMainFrame*)pMainFrame)->SetAddress(strUrl);
		percent= -1;	
	}
	m_nProgress = -1;
	m_lpszUrl = strUrl;

	//set icon
	if(pMainFrame!=NULL)
	{
		//mutex
//		WaitForSingleObject(m_hMutex, INFINITE);
		int nTabID = ((CMainFrame*)pMainFrame)->FindTab((CChildFrame*)GetParentFrame());
		
		if(m_nProgress>95 || m_nProgress<0)
		{
			int oi = oldIcon;
			if(IsActive)
			{
				if(((CChildFrame*)GetParentFrame())->bLock)
					oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( 4, nTabID );
				else if(((CChildFrame*)GetParentFrame())->bProtect)
					oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( 6, nTabID );
				else
					oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( -1, nTabID );

				//start to scroll
				if(!m_nScrollTimer && m_bUseAutoScroll && m_nSrSpeed!=0)
				{
					if(m_nProgress==100 || m_nProgress<0 || (!m_bScrollAfterDL && m_nProgress>=20))
					{
						m_nScrollTimer = SetTimer(2000, 1000*gSeed/m_nSrSpeed, NULL);
					}
				}

			}
			else
				oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( 5, nTabID );
			//update tab bar
			pMainFrame->PostMessage(WM_UPDATE_TAB);
		}

		//mutex
//		ReleaseMutex(m_hMutex);
	}

	//scroll bar
	if(m_nProgress==100 || m_nProgress<0)
	{
		LPDISPATCH pDisp = NULL;

		pDisp = GetHtmlDocument();
		IHTMLDocument2 *pHTMLDoc = NULL;
		IHTMLElement * pHTMLElem = NULL;
		IHTMLBodyElement *pHTMLBody = NULL;
		if( pDisp )
		{
			if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDoc)))
			{
				if(SUCCEEDED(pHTMLDoc->get_body( &pHTMLElem )))
				{
					if (SUCCEEDED(pHTMLElem->QueryInterface(IID_IHTMLBodyElement, (void**)&pHTMLBody)))
					{
						CString str="yes";
						BSTR bstr = str.AllocSysString();
						pHTMLBody->put_scroll(bstr);
						SysFreeString(bstr);

						pHTMLBody->Release();
					}
					pHTMLElem->Release();
				}
				pHTMLDoc->Release();
			}
			pDisp->Release();
		}
	}
}


void CMyIEView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD /*nFlags*/,
	LPCTSTR lpszTargetFrameName, CByteArray& baPostedData,
	LPCTSTR /*lpszHeaders*/, BOOL* pbCancel)
{
	//open in new window
	//get time
	LARGE_INTEGER liFinish;
	BOOL bCanNew = FALSE;
	if(bLinkInNewWin && m_tLastClick.LowPart != 0 && baPostedData.GetSize()==0)
	{
		QueryPerformanceCounter(&liFinish);
		LARGE_INTEGER liFreq;
		QueryPerformanceFrequency(&liFreq);
		double secs = (double)(liFinish.LowPart - m_tLastClick.LowPart)/(double)liFreq.LowPart;
		if(secs<0.5)
			bCanNew = TRUE;
		else
			m_tLastClick.LowPart = 0;
	}

	if(!m_bFirst && bLinkInNewWin && pMainFrame!=NULL && bCanNew)
	{
		if(strstr(lpszURL, "mailto:")==NULL && strstr(lpszURL, "javascript:")==NULL)
		{
			CWinApp* pApp = AfxGetApp();
			CChildFrame *pWnd = NULL;
			pWnd = ((CMainFrame*)pApp->m_pMainWnd)->NewChildWindow(0,1, NULL, this);
			if(pWnd != NULL)
			{
				pWnd->m_pView->dwProperty = dwProperty;

				pWnd->m_pView->m_IsNewPopup = TRUE;
				
				pWnd->m_pView->m_bFirst = TRUE;

				pWnd->m_pView->ToNavigate(lpszURL);

				*pbCancel = TRUE;

				return;
			}
		}

	}

	m_bFirst = FALSE;

	m_bForceRefresh =  FALSE;

⌨️ 快捷键说明

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