0

THIS IS NOT A HTML / JAVASCRIPT / CSS question!

Check out these images: X offset negligible; Y offset relevant

enter image description here

I need to get the HTML display area (aka viewport) offset to the 0/0 of the IE window.

  • I am targeting Microsoft Internet Explorer 11.
  • I am using C# with SHDocVw.InternetExplorer library to access/control the IE.

What I actually want to do is to trigger double-click events

  • similar to IHTMLElement.click(), just a doubleClick()
  • calling IHTMLElement.click() multiple times does not work

I tried to solve it WITHOUT actually clicking:

So right now I'm controlling the mouse to trigger certain events, calling [DllImport("user32.dll")] public static extern bool GetCursorPos(out PointInter lpPoint); and the like to get and set the mouse cursor and to simulate double-clicks on certain elements.

For the mouse navigation I already take into consideration

  • the OS's desktop zoom/scale setting
  • the IE window Left and Top properties
  • the location of the IHTMLElement(3).getClientBoundingRect, i.e. the position of the element I wanna trigger

This all works perfectly fine when the IE configuration is the same. My assumptions:

  • same HTML viewport offset (same toolbars, menus etc)
  • HTML viewport scaling 100% (no page zooming)

But those two factors are dynamic, so I have to account for them in some way.

So what I need is:

  • The HTML viewport's vertical offset (in both screenshots it's 106 pixels)
  • The HTML viewport's horizontal offset (in first its 1, in second it's 291)
  • The HTML viewport's zoom factor (in both screenshots 100%)

I have tried accessing multiple elements in the ShDocVw.InternetExplorer object, but I either have the wrong interface casts or it does not expose this information willingly, because I could not find it yet.

From a delve into the google world I also came up empty, so no (obvious) answers there either.

So does any one of you know how to deal with this problem? Some obscure COM/OLE incantations and rituals that could guide the mouse cursor on its way?

EDIT:

Dirty solution: I could display some homemade HTML/JS page first, that detects my simulated mouse movement and dump that information into some (invisible) div, then read that data in C#.

Though this is a solution, it's quite ugly and not useful for taking into account layout/display changes that might occur during later runtime, if user changes zooms while the app is working.

JayC667
  • 2,418
  • 2
  • 17
  • 31
  • I try to refer to the [docs](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752084(v=vs.85)) but it does not provide a direct way to access the viewport and zoom value. can you please inform us of the purpose of accessing the viewport and zoom? If you can inform your overall goal then it can help us to understand the issue properly. Other than that you can try to check the `Top` and `Left` property value of the browser window. See whether it returns helpful information for your requirement. – Deepak-MSFT Feb 04 '21 at 06:26
  • I updated my post to hopefully make it clearer. The overall goal is to raise double-click events on IHTMLElements. In the link I included in my post, I discuss that, but there have not been any answers yet. So in the meantime I use the dirty hack of controlling/simulating the mouse gestures (user32.dll) and make it double-click the actual elements. But for reliably obtaining the screen coordinates of an IHTMLElement, I need the HTML viewport offset INSIDE the IE window. IE's Top and Left values I am already using, as stated in my post. – JayC667 Feb 04 '21 at 10:49
  • I try to check the document for the IHTMLElement and found that it has a [click method](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752277(v=vs.85)) to simulates the click but it does not have a double click method. I did not get any other way to raise double click. So I think you need to stick with the workaround. – Deepak-MSFT Feb 05 '21 at 07:42
  • Yep. I'm using click already for a lot of other things, but click/click and click/sleep/click will both NOT trigger the dblick event... – JayC667 Feb 05 '21 at 13:56
  • Based on the [documents](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752279(v=vs.85)), what I want to say is that there is no official way available to simulate the IHTMLElement double click event. So you can continue with your workaround. – Deepak-MSFT Feb 09 '21 at 06:52

0 Answers0