Esempio n. 1
0
BOOL CChatView::PutBodyContent(const TCHAR * lpstrContent)
{
	//store body content
	if( lpstrContent) 
		m_lpstrBodyContent = lpstrContent;
	//check if HtmlDocument initialized
	if( m_pHtmlDoc2 && m_lpstrBodyContent )
	{
		HRESULT hr = S_OK;
		IHTMLElement *pBodyElement;
		//get body element
		hr=m_pHtmlDoc2->get_body( &pBodyElement);
		//put content to body element
		_bstr_t pbBody( m_lpstrBodyContent);
		hr=pBodyElement->put_innerHTML( pbBody);

		if( hr==S_FALSE) 
			return FALSE;
		else 
			return TRUE;
	}
	else 
		return FALSE;
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
// Name: SetElementInnerHtml
// Object: 
// Parameters :
//     in  : 
//     out : 
//     return : 
//-----------------------------------------------------------------------------
BOOL CHtmlViewer::SetElementInnerHtml(TCHAR* Id,TCHAR* Html)
{
    if (this->pIWebBrowser==NULL)
        return FALSE;

    if (!this->IsPageCompleted())
        return FALSE;

    HRESULT hr;
    BOOL bRet;
    IDispatch* pHtmlDocDispatch = NULL;
    IHTMLDocument3* pHtmlDoc = NULL;
    IHTMLElement* pElem = NULL;
    BSTR bstrElementId;
    BSTR bstrNewContent;

#if ((!defined(UNICODE))&& (!defined(_UNICODE)))
    WCHAR* psz;
#endif

    // get IDispatch document interface
    hr = pIWebBrowser->get_Document(&pHtmlDocDispatch);
    if (FAILED (hr) || (pHtmlDocDispatch == NULL))
        return FALSE;

    // get IHTMLDocument3 document interface
    hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument3,(void**)&pHtmlDoc);
    if (FAILED (hr) || (pHtmlDoc == NULL))
    {
        pHtmlDocDispatch->Release();
        return FALSE;
    }

    // get pointer to element from it's Id
#if (defined(UNICODE)||defined(_UNICODE))
    bstrElementId=SysAllocString(Id);
#else
    CAnsiUnicodeConvert::AnsiToUnicode(Id,&psz);
    bstrElementId=SysAllocString(psz);
    free(psz);    
#endif
    hr = pHtmlDoc->getElementById(bstrElementId,&pElem);
    SysFreeString(bstrElementId);
    if (FAILED (hr) || (pElem == NULL))
    {
        pHtmlDoc->Release();
        pHtmlDocDispatch->Release();
        return FALSE;
    }

    // set new content
#if (defined(UNICODE)||defined(_UNICODE))
    bstrNewContent=SysAllocString(Html);
#else
    CAnsiUnicodeConvert::AnsiToUnicode(Html,&psz);
    bstrNewContent=SysAllocString(psz);
    free(psz);    
#endif
    bRet=SUCCEEDED(pElem->put_innerHTML(bstrNewContent));
    SysFreeString(bstrNewContent);

    pElem->Release();
    pHtmlDoc->Release();
    pHtmlDocDispatch->Release();

    return bRet;
}