STDMETHODIMP CIEHlprObj::Invoke(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams,
VARIANT* pvarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
USES_CONVERSION;
strstream strEventInfo;
if (!pDispParams)
return E_INVALIDARG;
//
// Get the current URL.
//
LPOLESTR lpURL = NULL;
m_spWebBrowser2->get_LocationURL(&lpURL);
switch (dispidMember)
{
//
// The parameters for this DISPID are as follows:
// [0]: Cancel flag - VT_BYREF|VT_BOOL
// [1]: HTTP headers - VT_BYREF|VT_VARIANT
// [2]: Address of HTTP POST data - VT_BYREF|VT_VARIANT
// [3]: Target frame name - VT_BYREF|VT_VARIANT
// [4]: Option flags - VT_BYREF|VT_VARIANT
// [5]: URL to navigate to - VT_BYREF|VT_VARIANT
// [6]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event
//
case DISPID_BEFORENAVIGATE2:
strEventInfo << "BeforeNavigate2: ";
if (pDispParams->cArgs >= 5 &&
pDispParams->rgvarg[5].vt == (VT_BYREF|VT_VARIANT))
{
CComVariant varURL(*pDispParams->rgvarg[5].pvarVal);
varURL.ChangeType(VT_BSTR);
strEventInfo << OLE2T(varURL.bstrVal);
}
else
strEventInfo << "NULL";
strEventInfo << ends;
break;
//
// The parameters for this DISPID:
// [0]: URL navigated to - VT_BYREF|VT_VARIANT
// [1]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event
//
case DISPID_NAVIGATECOMPLETE2:
if (pDispParams->rgvarg[0].vt == (VT_BYREF|VT_VARIANT))
{
CComVariant varURL(*pDispParams->rgvarg[0].pvarVal);
varURL.ChangeType(VT_BSTR);
strEventInfo << "NavigateComplete2: "
<< OLE2T(varURL.bstrVal)
<< ends;
}
break;
//
// The parameters for this DISPID:
// [0]: New status bar text - VT_BSTR
//
case DISPID_STATUSTEXTCHANGE:
LPOLESTR lpStatusText;
m_spWebBrowser2->get_StatusText(&lpStatusText);
strEventInfo << "StatusTextChange: ";
if (!strcmp(OLE2T(lpStatusText), ""))
strEventInfo << "NULL";
else
strEventInfo << OLE2T(lpStatusText);
strEventInfo << ends;
break;
//
// The parameters for this DISPID:
// [0]: Maximum progress - VT_I4
// [1]: Amount of total progress - VT_I4
//
case DISPID_PROGRESSCHANGE:
strEventInfo << "ProgressChange: ";
if (pDispParams->cArgs == 0)
strEventInfo << "NULL";
else
{
if (pDispParams->rgvarg[0].vt == VT_I4)
strEventInfo << pDispParams->rgvarg[0].lVal;
if (pDispParams->cArgs > 1 &&
pDispParams->rgvarg[1].vt == VT_I4)
{
strEventInfo << ", " << pDispParams->rgvarg[1].lVal;
}
}
strEventInfo << ends;
break;
case DISPID_DOCUMENTCOMPLETE:
strEventInfo << "DocumentComplete" << ends;
break;
case DISPID_DOWNLOADBEGIN:
strEventInfo << "DownloadBegin" << ends;
break;
case DISPID_DOWNLOADCOMPLETE:
strEventInfo << "DownloadComplete" << ends;
break;
//
// The parameters for this DISPID:
// [0]: Enabled state - VT_BOOL
// [1]: Command identifier - VT_I4
//
case DISPID_COMMANDSTATECHANGE:
strEventInfo << "CommandStateChange: ";
if (pDispParams->cArgs == 0)
strEventInfo << "NULL";
else
{
if (pDispParams->rgvarg[0].vt == VT_BOOL)
{
strEventInfo << ((pDispParams->rgvarg[0].boolVal ==
VARIANT_TRUE) ? "True" : "False");
}
if (pDispParams->cArgs > 1 &&
pDispParams->rgvarg[1].vt == VT_I4)
{
strEventInfo << ", " << pDispParams->rgvarg[1].lVal;
}
}
strEventInfo << ends;
break;
case DISPID_NEWWINDOW2:
strEventInfo << "NewWindow2" << ends;
break;
//
// The parameters for this DISPID:
// [0]: Document title - VT_BSTR
//
case DISPID_TITLECHANGE:
strEventInfo << "TitleChange: ";
if (pDispParams->cArgs > 0 &&
pDispParams->rgvarg[0].vt == VT_BSTR)
{
strEventInfo << OLE2T(pDispParams->rgvarg[0].bstrVal);
}
else
{
strEventInfo << "NULL";
}
strEventInfo << ends;
break;
//
// The parameters for this DISPID:
// [0]: Name of property that changed - VT_BSTR
//
case DISPID_PROPERTYCHANGE:
strEventInfo << "PropertyChange: ";
if (pDispParams->cArgs > 0 &&
pDispParams->rgvarg[0].vt == VT_BSTR)
{
strEventInfo << OLE2T(pDispParams->rgvarg[0].bstrVal);
}
else
{
strEventInfo << "NULL";
}
strEventInfo << ends;
break;
//
// The parameters for this DISPID:
// [0]: Address of cancel flag - VT_BYREF|VT_BOOL
//
case DISPID_QUIT:
strEventInfo << "Quit" << ends;
ManageConnection(Unadvise);
m_dlgEvents.DestroyWindow();
break;
default:
strEventInfo << "Unknown Event" << dispidMember << ends;
break;
}
m_dlgEvents.AddEventToList(strEventInfo.str());
return S_OK;
}
이게 오버라이드 한 예제구요.. cpp 에 추가 하시구 헤더파일 클래스 안에다가
STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags,
DISPPARAMS * pdispparams, VARIANT * pvarResult,
EXCEPINFO * pexcepinfo, UINT * puArgErr);
이렇게 추가 해주시면 됩니다..