1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
// IWebBrowserEvents.cpp
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define MyDebug
#include <windows.h>
#include <cstdio>
#include <string>
#include "Main.h"
#include "IWebBrowserEvents.h"
#include "IWebBrowser.h"
extern "C" const IID LIBID_WebBrowser = {0xEAB22AC0,0x30C1,0x11CF,{0xA7,0xEB,0x00,0x00,0xC0,0x5B,0xAE,0x0B}};
extern "C" const IID IID_IWebBrowserEvents = {0x34A715A0,0x6587,0x11D0,{0x92,0x4A,0x00,0x20,0xAF,0xC7,0xAC,0x4D}};
#ifdef MyDebug
extern FILE* fp;
#endif
CEventSink::CEventSink() : m_cRef(0) //CEventSink Constructor
{
ITypeLib* pTypeLib=NULL;
HRESULT hr;
#ifdef MyDebug
fprintf(fp,"\n Entering CEventSink() Constructor!\n");
fprintf(fp," this = 0x%p\n",this);
#endif
this->m_pTypeInfo=NULL;
hr=LoadRegTypeLib(LIBID_WebBrowser,1,0,LANG_NEUTRAL,&pTypeLib);
if(SUCCEEDED(hr))
{
hr = pTypeLib->GetTypeInfoOfGuid(IID_IWebBrowserEvents, &m_pTypeInfo);
pTypeLib->Release();
}
#ifdef MyDebug
fprintf(fp," Leaving CEventSink() Constructor!\n\n");
#endif
}
CEventSink::~CEventSink()
{
#ifdef MyDebug
fprintf(fp," Entering CEventSink() Destructor!\n");
fprintf(fp," this->m_cRef = %ld\n",this->m_cRef);
#endif
if(this->m_pTypeInfo)
this->m_pTypeInfo->Release();
#ifdef MyDebug
fprintf(fp," Leaving CEventSink() Destructor!\n");
#endif
}
HRESULT CEventSink::QueryInterface(REFIID riid, void** ppv)
{
if(riid == IID_IUnknown)
*ppv = (IUnknown*)this;
else if(riid == IID_IDispatch)
*ppv = (IDispatch*)this;
else if(riid == IID_IWebBrowserEvents)
*ppv = (DWebBrowserEvents2*)this;
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
ULONG CEventSink::AddRef()
{
this->m_cRef++;
return this->m_cRef;
}
ULONG CEventSink::Release()
{
if(--m_cRef != 0)
return m_cRef;
else
delete this;
return 0;
}
HRESULT CEventSink::GetTypeInfoCount(UINT* pCountTypeInfo)
{
*pCountTypeInfo = 1;
return S_OK;
}
HRESULT CEventSink::GetTypeInfo(UINT iTypeInfo, LCID lcid, ITypeInfo** ppITypeInfo)
{
*ppITypeInfo = NULL;
if(iTypeInfo != 0)
return DISP_E_BADINDEX;
m_pTypeInfo->AddRef();
*ppITypeInfo = m_pTypeInfo;
return S_OK;
}
HRESULT CEventSink::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
{
if(riid != IID_NULL)
return DISP_E_UNKNOWNINTERFACE;
return DispGetIDsOfNames(m_pTypeInfo, rgszNames, cNames, rgDispId);
}
HRESULT CEventSink::Invoke(DISPID dispId, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDParms, VARIANT* pVarResult, EXCEPINFO* pErInfo, UINT* pErr)
{
if(riid != IID_NULL)
return DISP_E_UNKNOWNINTERFACE;
else
{
switch(dispId)
{
case 0xfc: // NavigateComplete2
{
this->NavigateComplete2(pDParms->rgvarg[1].pdispVal, pDParms->rgvarg[0].pvarVal);
break;
}
}
}
return S_OK;
}
void CEventSink::NavigateComplete2(IDispatch* pDisp, VARIANT* pVariantURL)
{
#ifdef MyDebug
fprintf(fp," Entering CEventSink::NavigateComplete2()\n");
fprintf(fp," pVariantURL->bstrVal = %S\n",pVariantURL->bstrVal);
fprintf(fp," Leaving CEventSink::NavigateComplete2()\n\n");
#else
MessageBox(NULL,pVariantURL->bstrVal,L"Received Event CEventSink::NavigateComplete2()",MB_ICONINFORMATION);
#endif
}
void CEventSink::StoreGridPointer(IWebBrowser* pIWebBrowser)
{
this->pWebBrowser=pIWebBrowser;
}
|