BOOL InjectDomNode(IWebBrowser *pWb,CString strJSUrl) { if (pWb == NULL) { return FALSE; } CComQIPtr<IHTMLDocument> pDoc; HRESULT hr = pWb->get_Document((IDispatch **)&pDoc); if ( FAILED(hr) || pDoc == NULL ) { return FALSE; } CComQIPtr<IHTMLDocument2> pDoc2(pDoc); if (pDoc2 == NULL) { return FALSE; } CComQIPtr<IHTMLBodyElement> pBody(pDoc2); pDoc2->get_body((IHTMLElement **)&pBody); if (pBody == NULL) { return FALSE; } CComQIPtr<IHTMLElement> pElem; CComQIPtr<IHTMLElement> pJscript; CComQIPtr<IHTMLDocument3> pDoc3 = pDoc; CComQIPtr<IDispatch> iDisp; CComBSTR PJsType = _T("script"); //javascript对象 hr = pDoc2->createElement(PJsType,&pJscript); //创建新元素对象 if(FAILED(hr) || !pJscript ) return FALSE; pJscript->setAttribute(CComBSTR("type"),CComVariant("text/javascript"),0); //设置JS类型 pJscript->setAttribute(CComBSTR("src"),CComVariant(strJSUrl),0); //设置JS类型 pJscript->setAttribute(CComBSTR("charset"),CComVariant("gb2312"),0); //pJscript->setAttribute(CComBSTR("defer"),CComVariant(VARIANT_TRUE),0); //设置加载延迟(必须的) //pJscript->setAttribute(CComBSTR("defer"),CComVariant("defer"),0); //设置加载延迟(必须的) CComQIPtr< IHTMLDOMNode, &IID_IHTMLDOMNode > pBodyNode(pBody); //转为节点对象 if(pBodyNode && pDoc) { CComQIPtr<IHTMLDOMNode,&IID_IHTMLDOMNode> pNewChild(pJscript); //转为节点对象 CComPtr<IHTMLDOMNode> pRefChild; hr = pBodyNode->appendChild(pNewChild, &pRefChild); //加载body页面后面 return hr==S_OK; } return E_FAIL; }
XMLConfigurationElement::XMLConfigurationElement(XMLConfiguration& _topParent, XMLConfigurationElement* _pParent, xmlNodePtr const _pNode) : m_topParent(_topParent) , m_pParent(_pParent) , m_isValid(false) { m_name = (char*)_pNode->name; m_value = (char*)(_pNode->content ? _pNode->content : (xmlChar*)""); xmlAttrPtr pProperty = _pNode->properties; while(pProperty != NULL) { std::string name = (char*)pProperty->name; // Get the property value in a kind of roundabout way. char* const pRawValue = (char*)xmlGetProp(_pNode, pProperty->name); std::string value = pRawValue ? pRawValue : ""; m_properties.insert(property_pair_type(name, value)); pProperty = pProperty->next; xmlFree(pRawValue); } // Iterate through the children xmlNodePtr pChild = _pNode->children; while(pChild != NULL) { ptr_type pNewChild(new XMLConfigurationElement(m_topParent, this, pChild)); this->addChild(pNewChild); m_topParent.dispatchEvent(pNewChild); pChild = pChild->next; } m_isValid = true; }