How to use GetDHtmlDocument() in MFC programming?

前端 未结 1 1599
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-23 04:26

I am trying to use

HRESULT GetDHtmlDocument(IHTMLDocument2 **pphtmlDoc);

function in MFC programming.

Basically, I am t

相关标签:
1条回答
  • 2021-01-23 04:50

    Your calling to GetDHtmlDocument() and GetElement() will return E_NOINTERFACE.

    According to my knowledge, you are not always guaranteed to have html document completely loaded when you're performing in CDHtmlDialog::OnInitDialog().

    Instead, you should override CDHtmlDialog::OnDocumentComplete() in CSampleProgramDlg. It's a callback function that'll be called when document is loaded. You can assess the document then.

    void CSampleProgramDlg::OnDocumentComplete(
       LPDISPATCH pDisp,
       LPCTSTR szUrl 
    )
    {
        // You can get the document and elements here safely
    }
    

    Your calling to MessageBox() may somehow trigger the document to be loaded in advance. Though I'm not 100% sure for it.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题