Sherry0

What is the easiest way to navigate the interfaces (in C++/ATL) to obtain the IHTMLObjectElement interface for my ActiveX Control plugin I can't guarantee anything about the object tag syntax on the html page - ie. no name= or id= or anything I could use as an identifier to find it in the DOM tree.

Thanks.


Re: Internet Explorer Extension Development From ActiveX Control to IHTMLObjectElement

Appxweb

One way you might do it (steps and pseudo code outline below)

1. Get the collection of all elements on the page

1.1 Get the Html document object
MSHTML::IHTMLDocument2Ptr sphtmlDoc;
MSHTML::IHTMLElementCollectionPtr sphtmlAll;
IDispatchPtr spDisp;
hr = m_pWebBrowser->get_Document(&spDisp);
hr = spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&sphtmlDoc);

1.2 Get the HTML element collection for the entire document

hr = sphtmlDoc->get_all(&sphtmlAll);
if (FAILED (hr) || sphtmlAll == NULL)
return hr;

2. Use this collection to get a collection of all object elements on the page

MSHTML::IHTMLElementCollectionPtr sphtmlObjects;
IDispatchPtr spDispObjects;

sphtmlAll->tags(CComVariant("OBJECT"), &spDispObjects);

3. Iterate this collection of objects until you find yours using the CLSID

long lCount = 0;
sphtmlObjects->get_length(&lCount);
for (long lCnt = 0; lCnt < lCount; lCnt++)
{
IDispatchPtr spdispObjectElem;

MSHTML::IHTMLObjectElementPtr spObject;
CComVariant varEmpty;
CComVariant varName;
varName.vt = VT_I4;
varName.lVal = lCnt;

spdispObjectElem = sphtmlObjects->item(varName, varEmpty);
varName.Clear();
varEmpty.Clear();

if (spdispObjectElem != NULL)
{
hr = spdispObjectElem->QueryInterface(__uuidof(MSHTML::IHTMLObjectElement), (void **) &spObject);

if (SUCCEEDED (hr) || spObject != NULL)
{
CString strCLSID;
BSTR bstrCLSID = NULL;
spObject->get_classid( &bstrCLSID);
strCLSID = bstrCLSID;
SysFreeString(bstrCLSID);

if(strCLSID=="Your CLISD)
{
//we have a match - use spObject to do what you need to

break; // need this to break the for loop
}
}
}

}

Regards

Ian