www.pudn.com > IEFilter.rar > IEFilterCtl.cpp
// IEFilterCtl.cpp : Implementation of the CIEFilterCtrl ActiveX Control class. #include "stdafx.h" #include "IEFilter.h" #include "IEFilterCtl.h" #include "IEFilterPpg.h" #include#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNCREATE(CIEFilterCtrl, COleControl) ///////////////////////////////////////////////////////////////////////////// // Message map BEGIN_MESSAGE_MAP(CIEFilterCtrl, COleControl) //{{AFX_MSG_MAP(CIEFilterCtrl) ON_WM_TIMER() //}}AFX_MSG_MAP ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // Dispatch map BEGIN_DISPATCH_MAP(CIEFilterCtrl, COleControl) //{{AFX_DISPATCH_MAP(CIEFilterCtrl) DISP_PROPERTY_EX(CIEFilterCtrl, "bCheckBody", GetBCheckBody, SetBCheckBody, VT_BOOL) DISP_PROPERTY_EX(CIEFilterCtrl, "Model", GetModel, SetModel, VT_I2) DISP_PROPERTY_EX(CIEFilterCtrl, "Enabled", GetEnabled, SetEnabled, VT_BOOL) DISP_PROPERTY_EX(CIEFilterCtrl, "bCheckURL", GetBCheckURL, SetBCheckURL, VT_BOOL) DISP_PROPERTY_EX(CIEFilterCtrl, "bCheckLocationName", GetBCheckLocationName, SetBCheckLocationName, VT_BOOL) DISP_PROPERTY_EX(CIEFilterCtrl, "bCheckTitle", GetBCheckTitle, SetBCheckTitle, VT_BOOL) DISP_FUNCTION(CIEFilterCtrl, "Init", Init, VT_EMPTY, VTS_NONE) DISP_FUNCTION(CIEFilterCtrl, "AddKey", AddKey, VT_EMPTY, VTS_BSTR) DISP_FUNCTION(CIEFilterCtrl, "Check", Check, VT_EMPTY, VTS_NONE) DISP_FUNCTION(CIEFilterCtrl, "AddAllowURL", AddAllowURL, VT_EMPTY, VTS_BSTR) DISP_FUNCTION(CIEFilterCtrl, "AddDenyURL", AddDenyURL, VT_EMPTY, VTS_BSTR) DISP_FUNCTION(CIEFilterCtrl, "getOthernessUrls", getOthernessUrls, VT_BSTR, VTS_NONE) DISP_FUNCTION(CIEFilterCtrl, "clnHisUrls", clnHisUrls, VT_EMPTY, VTS_NONE) DISP_PROPERTY_PARAM(CIEFilterCtrl, "bKillTIE", GetKillTIE, SetKillTIE, VT_BOOL, VTS_BOOL) //}}AFX_DISPATCH_MAP DISP_FUNCTION_ID(CIEFilterCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) END_DISPATCH_MAP() ///////////////////////////////////////////////////////////////////////////// // Event map BEGIN_EVENT_MAP(CIEFilterCtrl, COleControl) //{{AFX_EVENT_MAP(CIEFilterCtrl) // NOTE - ClassWizard will add and remove event map entries // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_EVENT_MAP END_EVENT_MAP() ///////////////////////////////////////////////////////////////////////////// // Property pages // TODO: Add more property pages as needed. Remember to increase the count! BEGIN_PROPPAGEIDS(CIEFilterCtrl, 1) PROPPAGEID(CIEFilterPropPage::guid) END_PROPPAGEIDS(CIEFilterCtrl) ///////////////////////////////////////////////////////////////////////////// // Initialize class factory and guid IMPLEMENT_OLECREATE_EX(CIEFilterCtrl, "IEFILTER.IEFilterCtrl.1", 0x8f9cc1b3, 0x1ce5, 0x401a, 0xa4, 0xd4, 0x7b, 0xa6, 0x7a, 0x75, 0xf, 0xc2) ///////////////////////////////////////////////////////////////////////////// // Type library ID and version IMPLEMENT_OLETYPELIB(CIEFilterCtrl, _tlid, _wVerMajor, _wVerMinor) ///////////////////////////////////////////////////////////////////////////// // Interface IDs const IID BASED_CODE IID_DIEFilter = { 0x68e42fda, 0x5a63, 0x4609, { 0xa9, 0x26, 0xd8, 0x2c, 0x19, 0xb4, 0xbf, 0xa4 } }; const IID BASED_CODE IID_DIEFilterEvents = { 0x692cb620, 0x1f79, 0x48b5, { 0x99, 0x68, 0x8b, 0xc6, 0x93, 0x7f, 0x3d, 0x77 } }; ///////////////////////////////////////////////////////////////////////////// // Control type information static const DWORD BASED_CODE _dwIEFilterOleMisc = OLEMISC_SETCLIENTSITEFIRST | OLEMISC_INSIDEOUT | OLEMISC_CANTLINKINSIDE | OLEMISC_RECOMPOSEONRESIZE; IMPLEMENT_OLECTLTYPE(CIEFilterCtrl, IDS_IEFILTER, _dwIEFilterOleMisc) ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl::CIEFilterCtrlFactory::UpdateRegistry - // Adds or removes system registry entries for CIEFilterCtrl BOOL CIEFilterCtrl::CIEFilterCtrlFactory::UpdateRegistry(BOOL bRegister) { // TODO: Verify that your control follows apartment-model threading rules. // Refer to MFC TechNote 64 for more information. // If your control does not conform to the apartment-model rules, then // you must modify the code below, changing the 6th parameter from // afxRegApartmentThreading to 0. if (bRegister) return AfxOleRegisterControlClass( AfxGetInstanceHandle(), m_clsid, m_lpszProgID, IDS_IEFILTER, IDB_IEFILTER, afxRegApartmentThreading, _dwIEFilterOleMisc, _tlid, _wVerMajor, _wVerMinor); else return AfxOleUnregisterClass(m_clsid, m_lpszProgID); } ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl::CIEFilterCtrl - Constructor CIEFilterCtrl::CIEFilterCtrl() { InitializeIIDs(&IID_DIEFilter, &IID_DIEFilterEvents); m_bKillTIE = true; m_bURL = true; m_bTitle = true; m_bLocationName = true; m_bBody = false; } ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl::~CIEFilterCtrl - Destructor CIEFilterCtrl::~CIEFilterCtrl() { // TODO: Cleanup your control's instance data here. } ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl::OnDraw - Drawing function void CIEFilterCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { // TODO: Replace the following code with your own drawing code. pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH))); pdc->Ellipse(rcBounds); } ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl::DoPropExchange - Persistence support void CIEFilterCtrl::DoPropExchange(CPropExchange* pPX) { ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor)); COleControl::DoPropExchange(pPX); // TODO: Call PX_ functions for each persistent custom property. } ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl::OnResetState - Reset control to default state void CIEFilterCtrl::OnResetState() { COleControl::OnResetState(); // Resets defaults found in DoPropExchange // TODO: Reset any other control state here. } ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl::AboutBox - Display an "About" box to the user void CIEFilterCtrl::AboutBox() { CDialog dlgAbout(IDD_ABOUTBOX_IEFILTER); dlgAbout.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CIEFilterCtrl message handlers void CIEFilterCtrl::Init() { // TODO: Add your dispatch handler code here CoInitialize(NULL); if (m_spSHWinds.CreateInstance(__uuidof(ShellWindows)) != S_OK) ::AfxMessageBox(_T("创建shellwindows失败")); clnHisUrls(); } BOOL CIEFilterCtrl::GetKillTIE(BOOL bKillTencentIE) { // TODO: Add your property handler here return m_bKillTIE; } void CIEFilterCtrl::SetKillTIE(BOOL bKillTencentIE, BOOL bNewValue) { // TODO: Add your property handler here m_bKillTIE = bNewValue; SetModifiedFlag(); } void CIEFilterCtrl::KillQQ_IExplorer() { if (m_bKillTIE) return; HWND hWnd = ::FindWindow("Internet Explorer_Hidden",NULL); if(hWnd != NULL) ::PostMessage(hWnd,WM_QUIT,0,0); } void CIEFilterCtrl::Checking() { if (m_spSHWinds == NULL || !m_bBody ) return; if(!m_Enabled) return; HRESULT hr; CString strCount; long nCount = m_spSHWinds->GetCount(); long i ,j ; strCount.Format("%i", nCount); m_strWinCount = strCount; CPtrArray ptrBrowserArray; SHDocVw::IWebBrowser2Ptr ptrBrowser_array[max_shellwindows_count]; int ptrBrowser_array_i = 0; IDispatchPtr spDisp; for ( i = 0; i < nCount; i++) { _variant_t va(i, VT_I4); int k = 0 ; BOOL b_checked = FALSE; spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); if(spBrowserArray.GetSize() > 100) spBrowserArray.RemoveAll(); for ( k = 0 ; k < this->spBrowserArray.GetSize() ;k++) { long ptrBrowserWndTMP ; long ptrBrowserWnd ; ptrBrowserWndTMP = spBrowserArray.GetAt(k); spBrowser->get_HWND(&ptrBrowserWnd); if (ptrBrowserWndTMP == ptrBrowserWnd ) { b_checked = TRUE; break; } } if (b_checked) continue;// 这是个旧窗口 已经被检查过了 if ( (k==0 || k == spBrowserArray.GetSize())&&spBrowser != NULL ) { long ptrBrowserWndTMP ; spBrowser->get_HWND(&ptrBrowserWndTMP); spBrowserArray.Add(ptrBrowserWndTMP); } if (spBrowser != NULL) { char * ptrLocationName; int pos = 0; char *pdest; CString s; MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument()); IHTMLElementCollection *pColl = NULL; MSHTML::IHTMLElement *pElem = NULL; if (spDoc != NULL) { //BODY & TBODY long over; CString DocS; LPDISPATCH pDispatch; char* body = 0; _variant_t tagName("BODY"); _variant_t tagNameT ("TBODY"); spDoc->get_all ((MSHTML::IHTMLElementCollection **)&pColl); pColl->get_length(&over); for (j = 0 ; j < --over;j++) { VARIANT vIndex; vIndex.vt = VT_UINT; vIndex.lVal = j; VARIANT var2 = {0}; wchar_t *wch; hr = pColl->item(vIndex,var2,&pDispatch); if(SUCCEEDED(hr)&& pDispatch !=NULL) { hr = pDispatch->QueryInterface(__uuidof(MSHTML::IHTMLElement),(void**) &pElem); pElem->get_tagName(&wch); _variant_t objtagName(wch); SysFreeString(wch); wch = NULL; if ( objtagName == tagName || tagNameT == objtagName ) { BSTR Text; pElem->get_innerText(&Text); ptrLocationName = _com_util::ConvertBSTRToString(Text); s.Format("%s",ptrLocationName); SysFreeString(Text); delete [] ptrLocationName; ptrLocationName = NULL; s.MakeLower(); for(j = 0; j < CStrArray.GetSize();j++) { CString sTemp = CStrArray.GetAt(j); pdest = strstr(s.GetBuffer (s.GetLength ()),sTemp.GetBuffer(sTemp.GetLength())); if (pdest != NULL) break; } if (pdest != NULL) { hr = spBrowser->QueryInterface(IID_IWebBrowser2, (void **)&ptrBrowser); if (FAILED(hr) && ptrBrowser != NULL) { spBrowser = NULL; } ptrBrowser_array[ptrBrowser_array_i++] = ptrBrowser; ptrBrowser->put_Visible(false); break; } } } } } // if(ptrBrowser != NULL) // ptrBrowser->Release(); } }//for i if (ptrBrowser_array_i > 0) { HWND hWnd; hWnd = ::GetForegroundWindow(); ::MessageBoxEx(hWnd,_T("对不起!您访问的事非法网页,这个网页被关闭"),NULL,0,NULL); } for(j = 0; j < ptrBrowser_array_i ; j++) { ptrBrowser->Stop(); Sleep(2000); ptrBrowser_array[j]->Quit(); } } void CIEFilterCtrl::URLChecking() { if (m_spSHWinds == NULL) return; HRESULT hr; CString strCount; long nCount = m_spSHWinds->GetCount(); long i ,j ; strCount.Format("%i", nCount); m_strWinCount = strCount; CPtrArray ptrBrowserArray; SHDocVw::IWebBrowser2Ptr ptrBrowser_array[max_shellwindows_count]; int ptrBrowser_array_i = 0; IDispatchPtr spDisp; for ( i = 0; i < nCount; i++) { _variant_t va(i, VT_I4); int k = 0 ; BOOL b_checked = FALSE; spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); if (spBrowser != NULL) { char * ptrLocationName; BSTR pbstrLocationURL; int pos = 0; char *pdest; CString s; // URL spBrowser->get_LocationURL(&pbstrLocationURL); ptrLocationName = _com_util::ConvertBSTRToString(pbstrLocationURL); SysFreeString(pbstrLocationURL); s.Format("%s",ptrLocationName); delete [] ptrLocationName; ptrLocationName = NULL; s.MakeLower(); for (j = 0 ; j QueryInterface(IID_IWebBrowser2, (void **)&ptrBrowser); if (FAILED(hr) && ptrBrowser != NULL) { spBrowser = NULL; } ptrBrowser_array[ptrBrowser_array_i++] = ptrBrowser; ptrBrowser->put_Visible(false); continue; } // if(ptrBrowser != NULL) // ptrBrowser->Release(); } }//for i if (ptrBrowser_array_i > 0) { HWND hWnd; hWnd = ::GetForegroundWindow(); ::MessageBoxEx(hWnd,_T("对不起!您访问的事非法网页,这个网页被关闭"),NULL,0,NULL); } for(j = 0; j < ptrBrowser_array_i ; j++) { ptrBrowser->Stop(); Sleep(1000); ptrBrowser_array[j]->Quit(); } } void CIEFilterCtrl::TitleChecking() { if (m_spSHWinds == NULL) return; HRESULT hr; CString strCount; long nCount = m_spSHWinds->GetCount(); long i ,j ; strCount.Format("%i", nCount); m_strWinCount = strCount; CPtrArray ptrBrowserArray; SHDocVw::IWebBrowser2Ptr ptrBrowser_array[max_shellwindows_count]; int ptrBrowser_array_i = 0; IDispatchPtr spDisp; for ( i = 0; i < nCount; i++) { _variant_t va(i, VT_I4); int k = 0 ; spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); if (spBrowser != NULL) { char * ptrLocationName; BSTR pbstrLocationURL; int pos = 0; char *pdest; CString s; MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument()); IHTMLElementCollection *pColl = NULL; MSHTML::IHTMLElement *pElem = NULL; if (spDoc != NULL) { pbstrLocationURL = spDoc->Gettitle(); ptrLocationName = _com_util::ConvertBSTRToString(pbstrLocationURL); s.Format("%s",ptrLocationName); delete [] ptrLocationName; ptrLocationName = NULL; s.MakeLower(); for(j = 0; j < CStrArray.GetSize();j++) { CString sTemp = CStrArray.GetAt(j); pdest = strstr(s.GetBuffer (s.GetLength ()),sTemp.GetBuffer(sTemp.GetLength())); if (pdest != NULL) break; } if (pdest != NULL ) { spBrowser->Stop(); hr = spBrowser->QueryInterface(IID_IWebBrowser2, (void **)&ptrBrowser); if (FAILED(hr)) { spBrowser = NULL; } ptrBrowser_array[ptrBrowser_array_i++] = ptrBrowser; ptrBrowser->put_Visible(false); continue ; } } } }//for i if (ptrBrowser_array_i > 0) { HWND hWnd; hWnd = ::GetForegroundWindow(); ::MessageBoxEx(hWnd,_T("对不起!您访问的事非法网页,这个网页被关闭"),NULL,0,NULL); } for(j = 0; j < ptrBrowser_array_i ; j++) { ptrBrowser->Stop(); Sleep(1000); ptrBrowser_array[j]->Quit(); } } void CIEFilterCtrl::LocationNameChecking() { if (m_spSHWinds == NULL) return; HRESULT hr; CString strCount; long nCount = m_spSHWinds->GetCount(); long i ,j ; strCount.Format("%i", nCount); m_strWinCount = strCount; CPtrArray ptrBrowserArray; SHDocVw::IWebBrowser2Ptr ptrBrowser_array[max_shellwindows_count]; int ptrBrowser_array_i = 0; IDispatchPtr spDisp; for ( i = 0; i < nCount; i++) { _variant_t va(i, VT_I4); int k = 0 ; spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); if (spBrowser != NULL) { char * ptrLocationName; BSTR pbstrLocationURL; int pos = 0; char *pdest; CString s; // LocationName ptrLocationName = _com_util::ConvertBSTRToString(spBrowser->GetLocationName()); s.Format("%s",ptrLocationName); delete [] ptrLocationName; s.MakeLower(); for(j = 0; j < CStrArray.GetSize();j++) { CString sTemp = CStrArray.GetAt(j); pdest = strstr(s.GetBuffer (s.GetLength ()),sTemp.GetBuffer(sTemp.GetLength())); if (pdest != NULL) break; } if (pdest != NULL) { hr = spBrowser->QueryInterface(IID_IWebBrowser2, (void **)&ptrBrowser); if (FAILED(hr) ) { spBrowser = NULL; } ptrBrowser_array[ptrBrowser_array_i++] = ptrBrowser; ptrBrowser->put_Visible(false); continue; } } }//for i if (ptrBrowser_array_i > 0) { HWND hWnd; hWnd = ::GetForegroundWindow(); ::MessageBoxEx(hWnd,_T("对不起!您访问的事非法网页,这个网页被关闭"),NULL,0,NULL); } for(j = 0; j < ptrBrowser_array_i ; j++) { ptrBrowser->Stop(); Sleep(1000); ptrBrowser_array[j]->Quit(); } } void CIEFilterCtrl::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default COleControl::OnTimer(nIDEvent); } void CIEFilterCtrl::AddKey(LPCTSTR Key) { // TODO: Add your dispatch handler code here CString s ; s = Key; CStrArray.Add (s); } void CIEFilterCtrl::Check() { // TODO: Add your dispatch handler code here if(!m_Enabled) return; if(m_bURL) URLChecking(); if(m_bLocationName) LocationNameChecking(); if(m_bTitle)TitleChecking(); if(m_bBody) Checking(); if(m_bKillTIE) KillQQ_IExplorer(); } BOOL CIEFilterCtrl::GetBCheckBody() { // TODO: Add your property handler here return m_bBody; } void CIEFilterCtrl::SetBCheckBody(BOOL bNewValue) { // TODO: Add your property handler here m_bBody = bNewValue; SetModifiedFlag(); } void CIEFilterCtrl::AddAllowURL(LPCTSTR URLSTR) { // TODO: Add your dispatch handler code here CString s ; s = URLSTR; CAllowURLArray.Add (s); } void CIEFilterCtrl::AddDenyURL(LPCTSTR DenyURL) { // TODO: Add your dispatch handler code here CString s ; s = DenyURL; this->CDenyURLArray.Add (s); } short CIEFilterCtrl::GetModel() { // TODO: Add your property handler here return m_Model; } void CIEFilterCtrl::SetModel(short nNewValue) { // TODO: Add your property handler here m_Model = (ModelType) nNewValue; SetModifiedFlag(); } BOOL CIEFilterCtrl::GetEnabled() { // TODO: Add your property handler here return m_Enabled; } void CIEFilterCtrl::SetEnabled(BOOL bNewValue) { // TODO: Add your property handler here m_Enabled = bNewValue; SetModifiedFlag(); } BOOL CIEFilterCtrl::GetBCheckURL() { // TODO: Add your property handler here return m_bURL; } void CIEFilterCtrl::SetBCheckURL(BOOL bNewValue) { // TODO: Add your property handler here m_bURL = bNewValue; SetModifiedFlag(); } BSTR CIEFilterCtrl::getOthernessUrls() { CString strResult; CString STmp; int i; for (i = COthernessUrlsArray.GetSize()-1 ; i >= 0 ; i-- ) { STmp = COthernessUrlsArray.GetAt(i); strResult = strResult + STmp +";"; } return strResult.AllocSysString(); } void CIEFilterCtrl::clnHisUrls() { // 清空所有访问过的历史url COthernessUrlsArray.RemoveAll(); } BOOL CIEFilterCtrl::GetBCheckLocationName() { // TODO: Add your property handler here return m_bLocationName; } void CIEFilterCtrl::SetBCheckLocationName(BOOL bNewValue) { // TODO: Add your property handler here this->m_bLocationName = bNewValue; SetModifiedFlag(); } BOOL CIEFilterCtrl::GetBCheckTitle() { // TODO: Add your property handler here return this->m_bTitle; } void CIEFilterCtrl::SetBCheckTitle(BOOL bNewValue) { // TODO: Add your property handler here m_bTitle = bNewValue; SetModifiedFlag(); }