BOOL SimpleBrowser::GetElementText(LPCTSTR elementName, LPTSTR bf, UINT bfLen) { IHTMLDocument3* pDocument = GetDocument3(); if (pDocument == NULL) return FALSE; BOOL bRet = FALSE; IHTMLElement* pElement = NULL; CComBSTR elemName = elementName; if (pDocument->getElementById(elemName, &pElement) == S_OK && pElement != NULL) { CComBSTR innerText; if (pElement->get_innerText(&innerText) == S_OK) { if (innerText.Length() > 0) { _tcsncpy(bf, innerText, bfLen); bf[bfLen - 1] = 0; } else bf[0] = 0; bRet = TRUE; } pElement->Release(); } pDocument->Release(); return bRet; }
HRESULT TestDocumentText(IHTMLDocument3 *pHtmlDoc, BSTR &message) { IHTMLDocument2 *pDoc = NULL; IHTMLElement *pElem = NULL; BSTR bstrId = SysAllocString(L"test"); HRESULT hr = pHtmlDoc->QueryInterface(IID_PPV_ARGS(&pDoc)); if (SUCCEEDED(hr) && pDoc) { hr = pDoc->get_body(&pElem); if (SUCCEEDED(hr) && pElem) { BSTR bstrText = NULL; pElem->get_innerText(&bstrText); message = SysAllocString(bstrText); SysFreeString(bstrText); pElem->Release(); } pDoc->Release(); } SysFreeString(bstrId); return hr; }