hopefully simple IE control question
-
I'm new to using the IE control (MSHTML) and am not sure how to do something. I know it should be possible. Here it is: If I have an object embedded in an HTML page and I display that page within the IE control, how do I get it programmatically? It has an ID and all of that.
tbContentElement
object? Any help, tips, or pointers to articles or whatever are/will be greatly appreciated. Thanks, Mike -
I'm new to using the IE control (MSHTML) and am not sure how to do something. I know it should be possible. Here it is: If I have an object embedded in an HTML page and I display that page within the IE control, how do I get it programmatically? It has an ID and all of that.
tbContentElement
object? Any help, tips, or pointers to articles or whatever are/will be greatly appreciated. Thanks, MikeYou must use IHTMLDocument2 interface. You can find some help on msdn.microsoft.com : http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/reference.asp example of function to retrieve the value of a tag in a html page : CString YourApp::GetTagValue(LPDISPATCH lpDispatch, CString strTagId) { CString strVal = ""; IHTMLDocument2* pHTMLDocument2 = NULL; if (lpDispatch == NULL) return ""; HRESULT hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pHTMLDocument2); lpDispatch->Release(); if (hr != S_OK) return ""; IHTMLElementCollection *pElementCollection = NULL; hr = pHTMLDocument2->get_all(&pElementCollection); if (hr != S_OK || pElementCollection == NULL) return ""; long nElt = 0; if (pElementCollection->get_length(&nElt) != S_OK) return ""; for (int i=0; iitem(varIndex, var2, &pDisp); if (hr == S_OK && pDisp != NULL) { IHTMLElement* pElem = NULL; hr = pDisp->QueryInterface(IID_IHTMLElement, (void**)&pElem); if (hr == S_OK && pElem != NULL) { BSTR bstrId = 0, bstrVal = 0; hr = pElem->get_id(&bstrId); CString strId(bstrId); strId.MakeLower(); // Oups, we find our tag !!! if (strId.Find(strTagId) != -1 && strId != "") { // Retrieve all html code pElem->get_innerHTML(&bstrVal); strVal = CString(bstrVal); } pElem->Release(); } pDisp->Release(); } } pElementCollection->Release(); return strVal; } you can use this function like this: CString strValue = GetTagValue(m_web.GetDocument(), "myid"); With a object embedded in a html page, I think you must use the IHTMLObjectElement interface instead of the IHTMLElement interface. This is not easy to play with the syntax of theses interfaces, but it works.... Good luck !!! ;)
-
You must use IHTMLDocument2 interface. You can find some help on msdn.microsoft.com : http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/reference.asp example of function to retrieve the value of a tag in a html page : CString YourApp::GetTagValue(LPDISPATCH lpDispatch, CString strTagId) { CString strVal = ""; IHTMLDocument2* pHTMLDocument2 = NULL; if (lpDispatch == NULL) return ""; HRESULT hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pHTMLDocument2); lpDispatch->Release(); if (hr != S_OK) return ""; IHTMLElementCollection *pElementCollection = NULL; hr = pHTMLDocument2->get_all(&pElementCollection); if (hr != S_OK || pElementCollection == NULL) return ""; long nElt = 0; if (pElementCollection->get_length(&nElt) != S_OK) return ""; for (int i=0; iitem(varIndex, var2, &pDisp); if (hr == S_OK && pDisp != NULL) { IHTMLElement* pElem = NULL; hr = pDisp->QueryInterface(IID_IHTMLElement, (void**)&pElem); if (hr == S_OK && pElem != NULL) { BSTR bstrId = 0, bstrVal = 0; hr = pElem->get_id(&bstrId); CString strId(bstrId); strId.MakeLower(); // Oups, we find our tag !!! if (strId.Find(strTagId) != -1 && strId != "") { // Retrieve all html code pElem->get_innerHTML(&bstrVal); strVal = CString(bstrVal); } pElem->Release(); } pDisp->Release(); } } pElementCollection->Release(); return strVal; } you can use this function like this: CString strValue = GetTagValue(m_web.GetDocument(), "myid"); With a object embedded in a html page, I think you must use the IHTMLObjectElement interface instead of the IHTMLElement interface. This is not easy to play with the syntax of theses interfaces, but it works.... Good luck !!! ;)