Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Get IHTMLDocument and OleObject

Post Reply
Lion85
Posts: 15
Joined: Tue Dec 06, 2022 9:19 am

Get IHTMLDocument and OleObject

Post by Lion85 »

Hello everyone,
is there by any chance a method to get from the browser IHTMLDocument and OleObject?
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get IHTMLDocument and OleObject

Post by salvadordf »

Hi,

IHTMLDocument is only available in TWebBrowser when it's configured to use Internet Explorer.

WebView2 doesn't have IHTMLDocument and you can only access the DOM using JavaScript at this moment.
Lion85
Posts: 15
Joined: Tue Dec 06, 2022 9:19 am

Re: Get IHTMLDocument and OleObject

Post by Lion85 »

Thank you for your reply!
In my old browser I had a code like this:

Code: Select all

IDispatch* pHtmlDoc = m_browser.get_Document();

CComPtr<IHTMLDocument2> pHtmlDocument2;
pHtmlDoc->QueryInterface(IID_IHTMLDocument2, (void**)&pHtmlDocument2));

CComPtr<IViewObject2> pViewObject;
pHtmlDocument2->QueryInterface(IID_IViewObject2, (void **)&pViewObject));
I can't find an alternative ...
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get IHTMLDocument and OleObject

Post by salvadordf »

Chromium based browsers have a much different API than Internet Explorer.

Read this for more details :
https://learn.microsoft.com/en-us/microsoft-edge/webview2/
https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/?view=webview2-1.0.1518.46

What do you want to do with pViewObject, pHtmlDocument2 and pHtmlDoc ?
Lion85
Posts: 15
Joined: Tue Dec 06, 2022 9:19 am

Re: Get IHTMLDocument and OleObject

Post by Lion85 »

I need to draw content above the browser window

Code: Select all

OleDraw(pViewObject.m_Obj, DVASPECT_CONTENT, DC, &cr);
DC is HDC and cr is RECT.
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get IHTMLDocument and OleObject

Post by salvadordf »

The WebView2 API doesn't expose any interface to draw over the browser but you can try a browser in "Windowless mode" and create a "Visual" over the browser.

The Windowless mode uses the DirectComposition API :
https://docs.microsoft.com/en-us/windows/win32/directcomp/directcomposition-portal

Check the WindowlessBrowser demo to see it working. I still have to fix some scaling issues in that demo when it runs in high DPI monitors.
Lion85
Posts: 15
Joined: Tue Dec 06, 2022 9:19 am

Re: Get IHTMLDocument and OleObject

Post by Lion85 »

I am still struggling with this problem.
I have tried this code. But I still can't solve it.. Would you have any advice?

Code: Select all

     
     "ICoreWebView2 * aWebView" //TO SHOW WHAT TYPE IT IS 
      IUnknown* oleObject = NULL;
      hr = aWebView->QueryInterface(IID_PPV_ARGS(&oleObject));
      if (SUCCEEDED(hr)) {
        RECT clientRect = { 0 };
        ::GetClientRect(HWND, &clientRect);
        HDC hdc = ::GetDC(HWND);
        OleDraw(oleObject, DVASPECT_CONTENT, hdc, &clientRect);
        ::ReleaseDC(HWND, hdc);

I've tried looking at 'WindowlessBrowser' but that's not what I'm looking for....
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get IHTMLDocument and OleObject

Post by salvadordf »

WebView2 doesn't support a pure "off-screen rendering mode" like CEF.
As far as I know, the only way to draw over a WebView2 browser is using the "Windowless mode".
Lion85
Posts: 15
Joined: Tue Dec 06, 2022 9:19 am

Re: Get IHTMLDocument and OleObject

Post by Lion85 »

Perfect thank you very much
Post Reply