描述:
我写了一个ocx,运行在网页内, 想在ocx中获取当前网页的URL地址,代码在网上找到了,
也能用,但是发现有个问题,在网页中用<object.../>和new ActiveXObject() 两种方式
载入ocx是,后种方式总是出错,请高手指点一下,不胜感激!
附代码(BCB的代码,AnsiString可看作VC的CString):
...
AnsiString __fastcall TMyOcxImpl::GetPageURL(void)
{
AnsiString s("");
try {
CComPtr<IOleContainer> iOct;
OleCheck(m_spClientSite->GetContainer(&iOct));
CComQIPtr<IHTMLDocument2,&IID_IHTMLDocument2> iDoc(iOct);
if(iDoc!=NULL)
{
CComBSTR url("");
OleCheck(iDoc->get_URL(&url));
s=AnsiString(url.Copy());
}
}
catch(...) {
s="";
}
return s;
}
解决方案1:
surely you can pass the url or even the HTML window object (external.menuArguments) to the activex control, but you may also implement IObjectWithSite to get the IWebBrowser2 interface. If your control supports this interface, Internet Explorer will call the SetSite method with a pointer, which may be used to query the webbrowser service via its IServiceProvider interface.
解决方案2: ActiveX created by using <object> is hosted by the DHTML Document object, which may supports IHTMLDocument2.
ActiveX created by using new ActiveXObject is hosted by the script engine.
您可能想查找下面的文章:
- Drag&Drop拖拽功能的实现问题,与IDataObject,IDataTarget相关的。急用,问题解决立即给分!!
- 哪位大哥大姐有《InsideTheC++ObjectModel》中文版的,麻烦送我一本吧!
- ActiveX中能导出自定义的数据结构吗?
- 关于自定义ActiveX方法的问题!
- "IInputObject”:没有与该对象关联的GUID——网上下的VC6的ATL代码在vc7下报这个错是怎么回事?
- 在ActiveX中使用CreateThread问题!
- 我有一个类CPerson,如何让它从CObject继承?在NewClass对话框的下拉列表里没有CObject类啊
- 使用shockwaveflash控件所出现的问题
- 已知com对象的classid,怎样获取对象所在dll的路径呢?
- 在mfc中如何获得ole嵌入对象的ioleobject接口?如何通过代码控制word对象