Page 1 of 1

Get IHTMLDocument and OleObject

Posted: Fri Jan 20, 2023 9:09 am
by Lion85
Hello everyone,
is there by any chance a method to get from the browser IHTMLDocument and OleObject?

Re: Get IHTMLDocument and OleObject

Posted: Fri Jan 20, 2023 9:31 am
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.

Re: Get IHTMLDocument and OleObject

Posted: Fri Jan 20, 2023 9:45 am
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 ...

Re: Get IHTMLDocument and OleObject

Posted: Fri Jan 20, 2023 9:53 am
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 ?

Re: Get IHTMLDocument and OleObject

Posted: Fri Jan 20, 2023 9:57 am
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.

Re: Get IHTMLDocument and OleObject

Posted: Sat Jan 21, 2023 1:46 pm
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.

Re: Get IHTMLDocument and OleObject

Posted: Fri Feb 10, 2023 10:58 am
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....

Re: Get IHTMLDocument and OleObject

Posted: Sat Feb 11, 2023 8:04 am
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".

Re: Get IHTMLDocument and OleObject

Posted: Mon Feb 13, 2023 8:34 am
by Lion85
Perfect thank you very much