?? 能夠阻攔訪問的瀏覽器.txt
字號(hào):
能夠阻攔訪問的瀏覽器
大家可能對(duì)IE內(nèi)的分級(jí)審查不陌生吧。所謂分級(jí)審查就是對(duì)瀏覽的網(wǎng)站加以限制,
限制其他人的使用。其實(shí)這個(gè)功能我們可以加入到我們的程序當(dāng)中。他是通過在
ChtmlView類中的
事件OnBeforeNavigate2()來實(shí)現(xiàn)的,這個(gè)事件可以在WEB瀏覽器中的導(dǎo)航發(fā)生
之前,引起事件。在產(chǎn)生這個(gè)事件以后,通過判斷網(wǎng)站的地址來加以阻攔。下面
是這個(gè)我的一段代
碼,我在視類中加入了一個(gè)CbyteArray類成員變量m_addlist,來記錄網(wǎng)址,通
過對(duì)這個(gè)數(shù)組中元素的判斷來停止瀏覽。
#include "stdafx.h"
#include "str.h"
#include "strDoc.h"
#include "strView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CStrView, CHtmlView)
BEGIN_MESSAGE_MAP(CStrView, CHtmlView)
//{{AFX_MSG_MAP(CStrView)
ON_COMMAND(IDD_DDE, OnDde)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CHtmlView::OnFilePrint)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStrView construction/destruction
CStrView::CStrView()
{
// TODO: add construction code here
} CStrView::~CStrView()
{
}
BOOL CStrView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CHtmlView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CStrView drawing
void CStrView::OnDraw(CDC* pDC)
{
CStrDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CStrView::OnInitialUpdate()
{
CHtmlView::OnInitialUpdate();
// TODO: This code navigates to a popular spot on the web.
// change the code to go where you'd like.
Navigate2(_T("http://263.NET"),NULL,NULL);
}
/////////////////////////////////////////////////////////////////////////////
// CStrView printing
/////////////////////////////////////////////////////////////////////////////
// CStrView diagnostics
#ifdef _DEBUG
void CStrView::AssertValid() const
{
CHtmlView::AssertValid();
}
void CStrView::Dump(CDumpContext& dc) const
{
CHtmlView::Dump(dc);
}
CStrDoc* CStrView::GetDocument()
// non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStrDoc)));
return (CStrDoc*)m_pDocument;
}
#endif//_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CStrView message handlers
void CStrView::OnDde()
{
CString ddd;
ddd="http://263.net";
m_addlist.Add( ddd);
//加入一個(gè)地址
}
void CStrView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel)
{
for(int i=0;i<=m_addlist.GetSize();i++)
{
CString temp;
temp=m_addlist.GetAt(i);
if(!strnicmp(lpszURL,temp,temp.GetLength()))
//判斷現(xiàn)在瀏覽的網(wǎng)頁與數(shù)組中的是否相同,如果相同將停止瀏覽該網(wǎng)頁并且
彈出一個(gè)對(duì)話框
{
*pbCancel=TRUE;
AfxMessageBox("這個(gè)網(wǎng)頁已經(jīng)被禁止瀏覽啦!^_^");
Stop(); break;
}
}
CHtmlView::OnBeforeNavigate2(lpszURL, nFlags, lpszTargetFrameName, baPostedData, lpszHeaders, pbCancel);
}
還可以在其中加入其他的事件,來達(dá)到你預(yù)期的效果。
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -