獲得ActiveX控制項所在網頁的資訊

來源:互聯網
上載者:User
基本上翻譯自以下兩文
http://support.microsoft.com/kb/172763/EN-US/#appliesto
http://support.microsoft.com/kb/181678

一. 獲得所在IE頁面的URL

1.    獲得IOleClientSite介面指標
2.    調用IOleClientSite::GetMoniker()獲得client site的moniker對象指標
3.    調用IMoniker::GetDisplayName()獲得當前文檔的URL

下面是ATL中獲得URL的常式,這裡是在SetClientSite中獲得,可以在其它任何時候獲得

STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
{
if (pClientSite != NULL)
{
// Obtain URL from container moniker.
CComPtr<IMoniker> spmk;
LPOLESTR pszDisplayName;

if (SUCCEEDED(pClientSite->GetMoniker(
OLEGETMONIKER_TEMPFORUSER,
OLEWHICHMK_CONTAINER,
&spmk)))
{
if (SUCCEEDED(spmk->GetDisplayName(
NULL, NULL, &pszDisplayName)))
{
USES_CONVERSION;

CComBSTR bstrURL;
bstrURL = pszDisplayName;

ATLTRACE("The current URL is %s/n", OLE2T(bstrURL));
CoTaskMemFree((LPVOID)pszDisplayName);
}
}
}

return IOleObject_SetClientSite(pClientSite);
}

在MFC中,可以重載COleControl::OnSetClientSite在設定ClientSite時就獲得URL

void CMyCtrl::OnSetClientSite(){
LPOLECLIENTSITE pClientSite = GetClientSite();
......//其它同上。
}

二.   訪問所在文檔的物件模型,即document,element等等東西

1.   獲得IWebBrowserApp,使用

a.使用IOleClientSite介面獲得IServiceProvider介面
CComQIPtr<IServiceProvider> pISP;
pClientSite->QueryInterface(IID_IServiceProvider,
(void **)&pISP);

b.使用IServiceProvider介面獲得IWebBrowserApp介面
pISP->QueryService(SID_SWebBrowserApp, IID_IWebBrowserApp,
(void **)&pIWebBrowserApp));

對於IE4或以後版本,也可以獲得IWebBrowserApp2介面
pISP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2,
(void **)&pIWebBrowser2));

2.使用IWebBrowserApp獲得文檔(document)對象,接著是其它對象。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.