HRESULT CBrowserHost::ShowMessage(HWND hwnd, LPOLESTR lpstrText, LPOLESTR lpstrCaption, DWORD dwType, LPOLESTR lpstrHelpFile, DWORD dwHelpContext, LRESULT *plResult) { USES_CONVERSION; TCHAR pBuffer[50]; // resource identifier for window caption "Microsoft Internet Explorer" #define IDS_MESSAGE_BOX_TITLE 2213 // Load Shdoclc.dll and the IE message box title string HINSTANCE hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL"));
if (hinstSHDOCLC == NULL) { //Error loading module -- fail as securely as possible return; }
LoadString(hinstSHDOCLC, IDS_MESSAGE_BOX_TITLE, pBuffer, 50); // Compare the IE message box title string with lpstrCaption // If they're the same, substitute your own Caption if (_tcscmp(OLE2T(lpstrCaption), pBuffer) == 0) lpstrCaption = L"New Caption"; // Create your own message box and display it *plResult = MessageBox(OLE2T(lpstrText), OLE2T(lpstrCaption), dwType); // Unload Shdoclc.dll and return FreeLibrary(hinstSHDOCLC); return S_OK; }
我严格按照http://msdn.microsoft.com/en-us/library/bb250489.aspx,用vs2005做了一遍,还是出现了同样的错误, 错误 1 error C2039: '_GetSinkMap' : is not a member of 'CHelloWorldBHO' e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 4137 为何????
error C2039: '_GetSinkMap' : is not a member of 'CHelloWorldBHO' e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 4137 ,问题已经解决.
我在添加IDocHostShowUI接口,写相关函数,总报错, class /*ATL_NO_VTABLE*/ CHelloWorldBHO : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>, public IObjectWithSiteImpl<CHelloWorldBHO>, public IDocHostUIHandler, public IDocHostShowUI, public IDispatchImpl<IHelloWorldBHO, &IID_IHelloWorldBHO, &LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0>, public IDispEventImpl<1, CHelloWorldBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1> 错误为 错误 1 error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 1792
再通知你的BHO
简单地插入下面代码在文档开头(OnDocumentComplete时)
<script>
var alert_api = window.alert;
window.alert = function alert_new(msg){
// 用一些办法像改变html某个元素文本,进行通告msg..
}
</script>
var alert_api = window.alert;
window.alert = function alert_new(msg){
// 用一些办法像改变html某个元素文本,进行通告msg..
....
// 调用原始window.alert,弹出message box..
alert_api(msg);
}
alert('ok');
</script>
完全可以通过其它方式
说说最原始需求
看了回帖,感觉楼主已经钻进牛角尖里去了
目前难点是如何实时捕捉对话框弹出事件。
HRESULT ShowMessage( HWND hwnd,
LPOLESTR lpstrText,
LPOLESTR lpstrCaption,
DWORD dwType,
LPOLESTR lpstrHelpFile,
DWORD dwHelpContext,
LRESULT *plResult
);
lpstrText中就是你想获得的弹出窗口内容,你在ShowMessage()函数中,想怎么玩就怎么玩
S_OK 不显示MSHTML的信息框,信息框由宿主在ShowMessage()函数中定制
S_FALSE 显示MSHTML的信息框
HRESULT CBrowserHost::ShowMessage(HWND hwnd,
LPOLESTR lpstrText,
LPOLESTR lpstrCaption,
DWORD dwType,
LPOLESTR lpstrHelpFile,
DWORD dwHelpContext,
LRESULT *plResult)
{
USES_CONVERSION;
TCHAR pBuffer[50]; // resource identifier for window caption "Microsoft Internet Explorer"
#define IDS_MESSAGE_BOX_TITLE 2213 // Load Shdoclc.dll and the IE message box title string
HINSTANCE hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL"));
if (hinstSHDOCLC == NULL)
{
//Error loading module -- fail as securely as possible
return;
}
LoadString(hinstSHDOCLC, IDS_MESSAGE_BOX_TITLE, pBuffer, 50); // Compare the IE message box title string with lpstrCaption
// If they're the same, substitute your own Caption
if (_tcscmp(OLE2T(lpstrCaption), pBuffer) == 0)
lpstrCaption = L"New Caption"; // Create your own message box and display it
*plResult = MessageBox(OLE2T(lpstrText), OLE2T(lpstrCaption), dwType); // Unload Shdoclc.dll and return
FreeLibrary(hinstSHDOCLC);
return S_OK;
}
不过还是谢谢
LPOLESTR lpstrText,
LPOLESTR lpstrCaption,
DWORD dwType,
LPOLESTR lpstrHelpFile,
DWORD dwHelpContext,
LRESULT *plResult
);
lpstrText中难道不是你想获得的弹出窗口内容?
以你有这方面的资料没,我现在ATL编写的bho,按照你说的我已经实现IDocHostShowUI::ShowMessage(),可是下一步不知道如何将其同BHO关联,IDocHostShowUI这方面我网上找了资料,搞不懂他同BHO的关系,能说下么,或者发些资料最好!!!!
class ATL_NO_VTABLE CHelloWorldBHO :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>,
public IObjectWithSiteImpl<CHelloWorldBHO>,
public IDispatchImpl<IHelloWorldBHO, &IID_IHelloWorldBHO, &LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
public IDispEventImpl<1, CHelloWorldBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>让CHelloWorldBHO这个类继承IDocHostShowUI接口。按照mshtml的架构,那么CHelloWorldBHO这个类就是宿主类。
实现CHelloWorldBHO::ShowMessage()和CHelloWorldBHO::ShowHelp()这两个函数。
在void STDMETHODCALLTYPE CHelloWorldBHO::OnDocumentComplete(IDispatch *pDisp, VARIANT *pvarURL)函数中的相应地方添加以下代码
if (m_spWebBrowser)
{
CComPtr<IDispatch> spDoc;
m_spWebBrowser->get_Document(&spDoc);
if (spDoc)
{
CComQIPtr<ICustomDoc, &IID_ICustomDoc> spCustomDoc(spDoc);
if (spCustomDoc)
spCustomDoc->SetUIHandler(this);
}
}
在CHelloWorldBHO::ShowMessage(HWND hwnd,
LPOLESTR lpstrText,
LPOLESTR lpstrCaption,
DWORD dwType,
LPOLESTR lpstrHelpFile,
DWORD dwHelpContext,
LRESULT *plResult)
函数中,传入的参数lpstrText就是mshtml的弹出信息框的内容。
这个很类似回调机制,不过mshtml是通过接口实现的。这个实现机理估计是这样:mshtml在弹出信息框前,会问:“宿主实现了IDocHostShowUI接口么?”而SetUIHandler告诉mshtml:“宿主是CHelloWorldBHO,它实现了IDocHostShowUI接口”,mshtml就会调用CHelloWorldBHO的ShowMessage(),并把要弹出的信息框内容以参数形式传进去,并根据ShowMessage()的返回值确定是否显示mshtml的缺省信息框。通过类似机理,宿主就可以控制mshtml的一切,当然也包括你想预先获得的弹出窗口的信息。
我怎么编译通过呀,atlcom.h(3699) : error C2039: '_GetSinkMap' : is not a member of 'CEyeOnIE'
以下是错误提示:
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2039: '_GetSinkMap' : is not a member of 'CEyeOnIE'
d:\lv\资料\test\eyeonie.h(17) : see declaration of 'CEyeOnIE'
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2065: '_GetSinkMap' : undeclared identifier
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2440: 'initializing' : cannot convert from 'int' to 'const struct ATL::_ATL_EVENT_ENTRY<class CEyeOnIE> *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
EyeOnIE.cpp
D:\lv\资料\test\EyeOnIE.cpp(181) : warning C4101: 'hwnd' : unreferenced local variable
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2039: '_GetSinkMap' : is not a member of 'CEyeOnIE'
d:\lv\资料\test\eyeonie.h(17) : see declaration of 'CEyeOnIE'
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2065: '_GetSinkMap' : undeclared identifier
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2440: 'initializing' : cannot convert from 'int' to 'const struct ATL::_ATL_EVENT_ENTRY<class CEyeOnIE> *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
这是怎么回事呀???
CEyeOnIE少定义了_GetSinkMap的相关宏
错误 1 error C2039: '_GetSinkMap' : is not a member of 'CHelloWorldBHO'
e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 4137 为何????
e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 4137 ,问题已经解决.
class /*ATL_NO_VTABLE*/ CHelloWorldBHO :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>,
public IObjectWithSiteImpl<CHelloWorldBHO>,
public IDocHostUIHandler,
public IDocHostShowUI,
public IDispatchImpl<IHelloWorldBHO, &IID_IHelloWorldBHO, &LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
public IDispEventImpl<1, CHelloWorldBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>
错误为
错误 1 error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 1792