Dipu KS
Dipu KS

Reputation: 63

Using CDHtmlDialog

I am using CDHtmlDialog to create a simple MFC app. I want my app to do the following things.

  1. Load images by using the MFC code to the DHTML page.

  2. Change texts in the DHTML page using the MFC code.

  3. Capture DHTML button cicks inside the MFC code and based on that change the images & texts.

For the 1 & 2 i am planning to do that inside a TIMER or Thread and dynmically change them for user.

I am able to make a simple app, but what am struggling with is changing the images & texts in DHTML page from the MFC code.

Can someone tell me how to do that?

A sample app or code will be great.

Thanks in advance.

Upvotes: 2

Views: 1761

Answers (1)

jon34560
jon34560

Reputation: 61

In the context of an extended CDHtmlDialog class you should be able to access and modify the dom elements with code like this:

IHTMLElement* pElement = NULL;
if(GetElement(_T("ELEMENT_BY_ID"), &pElement) == S_OK && pElement != NULL){

    // Get element html
    BSTR html = SysAllocString(_T(""));
    pElement->get_outerHTML(&html);

    // Update element html
    CString updatedHtml;
    updatedHTML.Format(_T("<div ID=\"ELEMENT_BY_ID\" >&nbsp; %s </div>"), _T("BLA")); 
    pElement->put_outerHTML(updatedHtml.AllocSysString());
}

To capture events you can register a handler that will fire when an element by id is clicked.

//
BEGIN_DHTML_EVENT_MAP(CYourDlg)
    DHTML_EVENT_ONCLICK(_T("ELEMENT_ID_TO_WATCH"), OnElementClickHandler)


protected:
HRESULT OnElementClickHandler(IHTMLElement *pElement);

HRESULT CYourDlg::OnElementClickHandler(IHTMLElement* /*pElement*/)
{
    return S_OK;
}

Upvotes: 1

Related Questions