Hi, Yes indeed IHTMLDocumentPtr is the starting point into the DOM. One thing that will help in the long run is to import the HTML type library - thus getting Visual Studio to generate wrappers around the numerous interfaces and methods. It wraps using smart pointers - so no QueryInterface/Releases to take care of. e.g. insert the following into either your header/implementation file
#import "C:\Windows\system32\mshtml.tlb" no_auto_exclude
This will generate two files, mshtml.tlh and mshtml.tli, in your project directory. The first is a header file, the next the implementation. With this done, here is a simple DHTML process from within MFC to get an element from the page...
void CWebDlg::OnDocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT FAR* URL)
{
USES_CONVERSION;
MSHTML::IHTMLDocument2Ptr spDoc(m\_ctlWeb1.GetDocument()); // This is the WebBrowser control
if (spDoc)
{
MSHTML::IHTMLDocument3Ptr spDoc3 = spDoc;
if (spDoc3)
{
MSHTML::IHTMLElementPtr spElem2 = spDoc3->getElementById(\_bstr\_t("idSpan1"));
if (spElem2)
{
CString strText = W2T(spElem2->innerText);
spElem2->innerText = \_bstr\_t("Hello There");
}
}
}
}
See how we can easily get the different interfaces of the object. The wrapper is doing the QI under the covers when we do a simple assignment. Plus the smart pointer will release that reference once the object goes out of scope. You can also easily create elements at will, e.g. here we create a BGSOUND element and append it to the DOM document.
MSHTML::IHTMLDocument2Ptr spDoc(m_ctlWeb1.GetDocument());
if (spDoc)
{
MSHTML::IHTMLElementPtr spElem = spDoc->createElement(_T("BGSOUND"));
if (spElem)
{
MSHTML::IHTMLBGsoundPtr spBG = spElem;
if (spBG)
{
CString strURL = _T("http://xyzxyz/snd/newalert.wav");
spBG->put_src((bstr_t)strURL);
MSHTML::IHTMLDOMNodePtr spBody = spDoc->body;
MSHTML::IHTMLDOMNodePtr spNode2Add = spBG;
// append new element to BODY
spBody->appendChild(spNode2Add);
}
}
}
To answer your question about inserting an image - I not too sure, something at the back of my mind does ring a bell about embedding IMG data in an HTML page. I'll see if I can find out. But for now I would think about saving the image to the file-system and then referencing the IMG src tag to the location. If you have any questions about DHTML or using MFC to generate DHTML I'll be happy to answer them. Hope this help