#include <exdispid.h>
#define _TBROWSER_NID_ 1
// Define the sWeb events to be handled:
static _ATL_FUNC_INFO StatusTextChangeInfo = {CC_STDCALL, VT_EMPTY, 1, {VT_BSTR}};
static _ATL_FUNC_INFO WindowResizeInfo = { CC_STDCALL, VT_EMPTY, 2, {VT_I4, VT_I4} };
static _ATL_FUNC_INFO DownloadBeginInfo = {CC_STDCALL, VT_EMPTY, 0, {NULL}};
static _ATL_FUNC_INFO WindowClosingInfo = { CC_STDCALL, VT_EMPTY, 2, { VT_BOOL, VT_BOOL } };
static _ATL_FUNC_INFO NewWindow2Info = {CC_STDCALL, VT_EMPTY, 2, {VT_BYREF|VT_BOOL,VT_BYREF|VT_DISPATCH}};
static _ATL_FUNC_INFO CommandStateChangeInfo = {CC_STDCALL, VT_EMPTY, 2, {VT_I4,VT_BOOL}};
static _ATL_FUNC_INFO BeforeNavigate2Info = {CC_STDCALL, VT_EMPTY, 7, {VT_DISPATCH,VT_BYREF|VT_VARIANT,VT_BYREF|VT_VARIANT,VT_BYREF|VT_VARIANT,VT_BYREF|VT_VARIANT,VT_BYREF|VT_VARIANT,VT_BYREF|VT_BOOL}};
static _ATL_FUNC_INFO ProgressChangeInfo = {CC_STDCALL, VT_EMPTY, 2, {VT_I4,VT_I4}};
static _ATL_FUNC_INFO NavigateComlete2Info = {CC_STDCALL, VT_EMPTY, 2, {VT_DISPATCH, VT_BYREF|VT_VARIANT}};
static _ATL_FUNC_INFO OnVisibleInfo = {CC_STDCALL, VT_EMPTY, 1, {VT_BOOL}};
template <class T/*, _ATL_FUNC_INFO* info*/>
class TBrowserEvents : public IDispEventSimpleImpl<_TBROWSER_NID_, TBrowserEvents<T>, &DIID_DWebBrowserEvents2>
{
protected:
IWebBrowser2* mWebBrowser;
BOOL mInitial;
//DECLARE_DYNCREATE( TBrowserEvents<T> )
//DECLARE_EVENTSINK_MAP()
void OnWindowClosing( BOOL bIsChildWindow, BOOL* pbCancel );
public:
BEGIN_SINK_MAP(TBrowserEvents)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 102, __StatusTextChange, &StatusTextChangeInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 108, __ProgressChange, &ProgressChangeInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, DISPID_WINDOWRESIZE, __WindowResize, &ProgressChangeInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 105, __CommandStateChange, &CommandStateChangeInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 106, __DownloadBegin, &DownloadBeginInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 104, __DownloadComplete, &DownloadBeginInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 113, __TitleChange, &StatusTextChangeInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 252, __NavigateComplete2, &NavigateComlete2Info)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 250, __BeforeNavigate2, &BeforeNavigate2Info)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 112, __PropertyChange, &StatusTextChangeInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, DISPID_NEWWINDOW2,/* 251,*/ __NewWindow2, &NewWindow2Info)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 259, __DocumentComplete, &NavigateComlete2Info)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, DISPID_ONQUIT, __OnQuit, &DownloadBeginInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 254, __OnVisible, &OnVisibleInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 255, __OnToolBar, &OnVisibleInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 256, __OnMenuBar, &OnVisibleInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 257, __OnStatusBar, &OnVisibleInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 258, __OnFullScreen, &OnVisibleInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, 260, __OnTheaterMode, &OnVisibleInfo)
SINK_ENTRY_INFO(_TBROWSER_NID_, DIID_DWebBrowserEvents2, DISPID_WINDOWCLOSING, __OnWindowClosing, &WindowClosingInfo)
SINK_ENTRY_EX( _TBROWSER_NID_, DIID_DWebBrowserEvents2, DISPID_QUIT, __Quit)
END_SINK_MAP()
T* mOwner;
TBrowserEvents(T* Owner, IWebBrowser2* pWebBrowser)
{
initialize( Owner, pWebBrowser );
}
TBrowserEvents()
{
}
void initialize( T* Owner, IWebBrowser2* pWebBrowser )
{
mWebBrowser = pWebBrowser;
DispEventAdvise( dynamic_cast<IUnknown*>(mWebBrowser) );
mInitial = TRUE;
mOwner = Owner;
}
~TBrowserEvents(void)
{
DispEventUnadvise( dynamic_cast<IUnknown*>(mWebBrowser) );
}
void __stdcall __StatusTextChange(/*[in]*/ BSTR bstrText) { }
void __stdcall __ProgressChange(/*[in]*/ long progress, /*[in]*/ long progressMax) { }
void __stdcall __WindowResize(/*[in]*/ long progress, /*[in]*/ long progressMax) { }
void __stdcall __CommandStateChange(/*[in]*/ long Command, /*[in]*/ VARIANT_BOOL Enable) { }
void __stdcall __DownloadBegin() { }
void __stdcall __DownloadComplete() { }
void __stdcall __TitleChange(/*[in]*/ BSTR bstrText) { }
void __stdcall __NavigateComplete2(/*[in]*/ IDispatch* pDisp, /*[in]*/ VARIANT* URL) { }
void __stdcall __BeforeNavigate2(/*[in]*/ IDispatch* pDisp, /*[in]*/ VARIANT* URL, /*[in]*/ VARIANT* Flags,
/*[in]*/ VARIANT* TargetFrameName, /*[in]*/ VARIANT* PostData, /*[in]*/ VARIANT* Headers,
/*[out]*/ VARIANT_BOOL* Cancel) { }
void __stdcall __PropertyChange(/*[in]*/ BSTR bstrProperty) { }
void __stdcall __NewWindow2(/*[out]*/ IDispatch** ppDisp, /*[out]*/ VARIANT_BOOL* Cancel) { }
void __stdcall __DocumentComplete(/*[in]*/ IDispatch* pDisp, /*[in]*/ VARIANT* URL) { }
void __stdcall __OnQuit() { }
void __stdcall __Quit() { }
//void __stdcall __OnWindowClosing() { }
void __stdcall __OnVisible(/*[in]*/ VARIANT_BOOL Visible) { }
void __stdcall __OnToolBar(/*[in]*/ VARIANT_BOOL ToolBar) { }
void __stdcall __OnMenuBar(/*[in]*/ VARIANT_BOOL MenuBar) { }
void __stdcall __OnStatusBar(/*[in]*/ VARIANT_BOOL StatusBar) { }
void __stdcall __OnFullScreen(/*[in]*/ VARIANT_BOOL FullScreen) { }
void __stdcall __OnTheaterMode(/*[in]*/ VARIANT_BOOL TheaterMode) { }
void __stdcall __OnWindowClosing( VARIANT_BOOL IsChildWindow, VARIANT_BOOL* Cancel ) { }
};
아공 만타..
함수 인자가 틀리면 에러 난다..
적용은 이런 식으로
TBrowserEvents<CMainDlg>* mEvent;
mEvent = new TBrowserEvents<CMainDlg>(this, pWB2);
pWB2 는 IWebBrowser2임..
이벤트 처리는 이런 식으로
void TBrowserEvents<CMainDlg>::__DocumentComplete(/*[in]*/ IDispatch* pDisp, /*[in]*/ VARIANT* URL)
{
//< @ summary : 로그인 처리하는 부분을 넣어야 함..
mOwner->documentCmpl( );
}
void TBrowserEvents<CMainDlg>::__NewWindow2(/*[out]*/ IDispatch** ppDisp, /*[out]*/ VARIANT_BOOL* Cancel)
{
mOwner->popup( ppDisp, Cancel );
}