📄 pub.h
字号:
//
// Popup Blocker Version 2.0
// Copyright (c) 2003 Osborn Technologies, Inc. All rights reserved.
// Web: http://www.osborntech.com
// Email: mailto:info@osborntech.com
//
// This software is being provided to you, the LICENSEE, by
// Osborn Technologies under the following license. By obtaining,
// using and/or copying this software, you agree that you have read,
// understood, and will comply with these terms and conditions:
//
// Permission to use, copy, modify and distribute this software and
// its documentation for any purpose and without fee or royalty is
// hereby granted, provided that you agree to comply with the
// following copyright notice and statements, including the
// disclaimer, and that the same appear on ALL copies of the
// software and documentation, including modifications that you make
// for internal use or for distribution.
//
// Popup Blocker Version 2.0 Copyright ?2003 by Osborn Technologies. All rights reserved.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND OSBORN TECHNOLOGIES MAKES
// NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF
// EXAMPLE, BUT NOT LIMITATION, OSBORN TECHNOLOGIES MAKES NO
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
// ANY PARTICULAR PURPOSE, OR THAT THE FUNCTIONS CONTAINED IN THIS
// SOFTWARE WILL MEET YOUR REQUIREMENTS OR EXPECTATIONS, OR THAT THE
// OPERATION OF THIS SOFTWARE WILL BE ENTIRELY ERROR FREE OR APPEAR
// PRECISELY AS DESCRIBED IN THE SOFTWARE DOCUMENTATION, OR THAT THE
// USE OF THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE
// ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
//
// The name of Osborn Technologies may not be used in advertising or
// publicity pertaining to distribution of this software. Title to
// copyright in this software and any associated documentation shall
// at all times remain with Osborn Technologies and LICENSEE agrees
// to preserve same.
//
#pragma once
#include "resource.h" // main symbols
#include <gdiplus.h>
#include <deque>
// IPub
[
object,
uuid("6C51F7E9-8542-4F25-A30F-2060157752E1"),
dual, helpstring("IPub Interface"),
pointer_default(unique)
]
__interface IPub : IDispatch
{
};
// CPub
[
coclass,
threading("apartment"),
support_error_info("IPub"),
aggregatable("never"),
vi_progid("OsbornTech.PopupBlocker"),
progid("OsbornTech.PopupBlocker.1"),
version(1.0),
uuid("C68AE9C0-0909-4DDC-B661-C1AFB9F5AE53"),
helpstring("PopupBlocker Class")
]
class ATL_NO_VTABLE CPub :
public IObjectWithSiteImpl<CPub>,
public IDispatchImpl<IPub, &__uuidof(IPub)>,
public IDocHostUIHandler,
public IOleCommandTarget,
public IPropertyNotifySink
{
public:
CPub() :
m_hwndIE(NULL),
m_hHook(NULL),
m_bHotkeysEnabled(TRUE),
m_bBlockNewWindow(TRUE),
m_dwBrowserCookie(0),
m_dwDocumentCookie(0),
m_dwWindowCookie(0),
m_dwPropNotifyCookie(0),
m_pWBDisp(NULL),
m_hMutex(NULL),
m_hMutexOptions(NULL),
//m_bUserClickedLink(FALSE),
m_timeClick(0),
m_bUnloading(FALSE),
m_lpResizeOldWndProc(NULL),
m_bShuttingDown(FALSE),
m_gdiplusToken(0),
m_pHTMLWindow(NULL)
{
}
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
m_hMutex = CreateMutex(NULL, FALSE, _T("MutexToProtectPubData"));
if (m_hMutex == NULL)
{
AtlMessageBox(NULL, IDS_ERR_CREATEMUTEX, IDS_PROJNAME);
DWORD dwErr = GetLastError();
return HRESULT_FROM_WIN32(dwErr);
}
m_hMutexOptions = CreateMutex(NULL, FALSE, _T("MutexForOptionsDlg"));
if (m_hMutexOptions == NULL)
{
AtlMessageBox(NULL, IDS_ERR_CREATEMUTEX, IDS_PROJNAME);
DWORD dwErr = GetLastError();
return HRESULT_FROM_WIN32(dwErr);
}
LoadRegistrySettings();
return S_OK;
}
void FinalRelease()
{
ATLTRACE(_T("FinalRelease\n"));
}
public:
//
// IDispatch Methods
//
STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS * pdispparams, VARIANT * pvarResult,
EXCEPINFO * pexcepinfo, UINT * puArgErr);
//
// IOleObjectWithSite Methods
//
STDMETHOD(SetSite)(IUnknown *pUnkSite);
//
// IDocHostUIHandler
//
STDMETHOD(ShowContextMenu)(DWORD dwID, POINT FAR* ppt, IUnknown FAR* pcmdTarget, IDispatch FAR* pdispReserved);
STDMETHOD(ShowUI)(DWORD dwID, IOleInPlaceActiveObject FAR* pActiveObject,
IOleCommandTarget FAR* pCommandTarget,
IOleInPlaceFrame FAR* pFrame,
IOleInPlaceUIWindow FAR* pDoc)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->ShowUI(dwID, pActiveObject, pCommandTarget, pFrame, pDoc);
return S_FALSE;
}
STDMETHOD(GetHostInfo)(DOCHOSTUIINFO FAR *pInfo)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->GetHostInfo(pInfo);
return S_OK;
}
STDMETHOD(HideUI)(void)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->HideUI();
return S_OK;
}
STDMETHOD(UpdateUI)(void)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->UpdateUI();
return S_OK;
}
STDMETHOD(EnableModeless)(BOOL fEnable)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->EnableModeless(fEnable);
return S_OK;
}
STDMETHOD(OnDocWindowActivate)(BOOL fActivate)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->OnDocWindowActivate(fActivate);
return S_OK;
}
STDMETHOD(OnFrameWindowActivate)(BOOL fActivate)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->OnFrameWindowActivate(fActivate);
return S_OK;
}
STDMETHOD(ResizeBorder)(LPCRECT prcBorder, IOleInPlaceUIWindow FAR* pUIWindow, BOOL fFrameWindow)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->ResizeBorder(prcBorder, pUIWindow, fFrameWindow);
return S_OK;
}
STDMETHOD(TranslateAccelerator)(LPMSG lpMsg, const GUID FAR* pguidCmdGroup, DWORD nCmdID)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->TranslateAccelerator(lpMsg, pguidCmdGroup, nCmdID);
return E_NOTIMPL;
}
STDMETHOD(GetOptionKeyPath)(LPOLESTR FAR* pchKey, DWORD dw)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->GetOptionKeyPath(pchKey, dw);
return E_FAIL;
}
STDMETHOD(GetDropTarget)(IDropTarget* pDropTarget, IDropTarget** ppDropTarget)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->GetDropTarget(pDropTarget, ppDropTarget);
return S_OK;
}
STDMETHOD(GetExternal)(IDispatch** ppDispatch)
{
// IE will call this when the user asks for the external dispatch
// of the window, either via script (window.external) or via
// the Tools menu.
if (m_spExtDispatch)
return m_spExtDispatch.CopyTo(ppDispatch);
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->GetExternal(ppDispatch);
return S_FALSE;
}
STDMETHOD(TranslateUrl)(DWORD dwTranslate, OLECHAR* pchURLIn, OLECHAR** ppchURLOut)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->TranslateUrl(dwTranslate, pchURLIn, ppchURLOut);
return S_FALSE;
}
STDMETHOD(FilterDataObject)(IDataObject* pDO, IDataObject** ppDORet)
{
if (m_spDefaultDocHostUIHandler)
return m_spDefaultDocHostUIHandler->FilterDataObject(pDO, ppDORet);
return S_FALSE;
}
//
// IOleCommandTarget methods
//
STDMETHOD(QueryStatus)(
/*[in]*/ const GUID *pguidCmdGroup,
/*[in]*/ ULONG cCmds,
/*[in,out][size_is(cCmds)]*/ OLECMD *prgCmds,
/*[in,out]*/ OLECMDTEXT *pCmdText)
{
if (m_spDefaultOleCommandTarget)
return m_spDefaultOleCommandTarget->QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
return S_OK;
}
STDMETHOD(Exec)(
/*[in]*/ const GUID *pguidCmdGroup,
/*[in]*/ DWORD nCmdID,
/*[in]*/ DWORD nCmdExecOpt,
/*[in]*/ VARIANTARG *pvaIn,
/*[in,out]*/ VARIANTARG *pvaOut)
{
if (nCmdID == OLECMDID_SHOWSCRIPTERROR)
{
// Don't show the error dialog, but
// continue running scripts on the page.
(*pvaOut).vt = VT_BOOL;
(*pvaOut).boolVal = VARIANT_TRUE;
return S_OK;
}
if (m_spDefaultOleCommandTarget)
return m_spDefaultOleCommandTarget->Exec(pguidCmdGroup, nCmdID, nCmdExecOpt, pvaIn, pvaOut);
return S_OK;
}
//
// IPropertyNotifySink methods
//
STDMETHOD(OnChanged)(DISPID dispID);
STDMETHOD(OnRequestEdit)(DISPID dispID){return S_OK;}
private:
class CConnInfo
{
public:
CConnInfo(IDispatch* pWBDisp) :
m_spWBDisp(pWBDisp),
m_dwDocumentCookie(0),
m_dwWindowCookie(0)
{
}
CComPtr<IDispatch> m_spWBDisp;
DWORD m_dwDocumentCookie;
DWORD m_dwWindowCookie;
};
private:
// Handle to IE main window
HWND m_hwndIE;
// Keyboard hook handle
HHOOK m_hHook;
// Hotkey toggle
BOOL m_bHotkeysEnabled;
// TRUE if blocking new windows
BOOL m_bBlockNewWindow;
// TRUE if the user clicked a link
DWORD m_timeClick;
// TRUE if the page is about to be unloaded
BOOL m_bUnloading;
// Connection Tokens - used for Advise and Unadvise
DWORD m_dwBrowserCookie;
DWORD m_dwDocumentCookie;
DWORD m_dwWindowCookie;
DWORD m_dwPropNotifyCookie;
// Smart pointer to browser
CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2;
// Smart pointer to the document
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> m_spHTMLDocument;
// Smart pointer to the document window
IHTMLWindow2* m_pHTMLWindow;
// Top-level web browser IDispatch*
LPDISPATCH m_pWBDisp;
// Smart pointer to IDispatch of object handling
CComQIPtr<IDispatch> m_spExtDispatch;
// Smart pointer to IDispatch of HTMLDocumentEvent handler
CComQIPtr<IDispatch> m_spDocEventDisp;
// Smart pointer to IDispatch of HTMLWindowEvent handler
CComQIPtr<IDispatch> m_spWindowEventDisp;
std::deque<CConnInfo*> m_deqEventHandlers;
// Default interface pointers
CComQIPtr<IDocHostUIHandler, &IID_IDocHostUIHandler> m_spDefaultDocHostUIHandler;
CComQIPtr<IOleCommandTarget, &IID_IOleCommandTarget> m_spDefaultOleCommandTarget;
// Access control
HANDLE m_hMutex;
HANDLE m_hMutexOptions;
// TRUE if Popup Blocker is closing
BOOL m_bShuttingDown;
Gdiplus::GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_gdiplusToken;
public:
WNDPROC m_lpResizeOldWndProc;
private:
static LRESULT CALLBACK ResizeWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK IEKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
HRESULT ManageBrowserConnection(ConnectType eConnectType);
HRESULT ManageEventHandlers(CConnInfo* pConnInfo, ConnectType eConnectType);
HRESULT ManagePropertyNotifyConnection(ConnectType eConnectType);
void LoadRegistrySettings();
void EnablePopupBlocker();
void NotifiyUser();
void UpdateStats(BSTR bsUrl);
void BlockWebPageElements(DWORD dwElemTypes);
void NavigateToSafePage();
UINT GetKeyState();
BOOL KeyMatch(UINT nState, WPARAM wParam, int nKey);
public:
BOOL IsEnabled();
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -