mshtml.IHTMLElement的位置给出了意想不到的结果 [英] Position of mshtml.IHTMLElement gives unexpected result

查看:385
本文介绍了mshtml.IHTMLElement的位置给出了意想不到的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要确定mshtml.HtmlDocument树中所有DOM元素的确切坐标。

我使用mshtml.IHTMLElement.offsetTop和offsetLeft结合IHTMLElement.offsetParent
分别使用mshtml.IHTMLElement2.getBoundingClientRect()来计算元素的位置。
/>代码片段:

mshtml.IHTMLElement htmlElem;
mshtml.IHTMLElement htmlOffsetParent;
MyPosition position;

position.hbsoluteTop = htmlElem.offsetTop;
position.AbsoluteLeft = htmlElem.offsetLeft;

Hi

I need to determine the exact coordinates for all DOM elements in a mshtml.HtmlDocument tree. 

I use mshtml.IHTMLElement.offsetTop and offsetLeft in combination with IHTMLElement.offsetParent
rspectively mshtml.IHTMLElement2.getBoundingClientRect() to figure out the position of a element.

Code snippet:

mshtml.IHTMLElement htmlElem;
mshtml.IHTMLElement htmlOffsetParent;
MyPosition position;

position.AbsoluteTop = htmlElem.offsetTop;
position.AbsoluteLeft = htmlElem.offsetLeft;

htmlOffsetParent = htmlElem.offsetParent;

htmlOffsetParent = htmlElem.offsetParent;

while(htmlOffsetParent!= null)
{
position.AbsoluteTop + = htmlOffsetParent.offsetTop;
position.AbsoluteLeft + = htmlOffsetParent.offsetLeft;

while (htmlOffsetParent != null)
{
 position.AbsoluteTop += htmlOffsetParent.offsetTop;
 position.AbsoluteLeft += htmlOffsetParent.offsetLeft;

htmlOffsetParent = htmlOffsetParent.offsetParent;
}

类MyPosition
{
公共Int32 AbsoluteTop;
公共Int32 AbsoluteLeft;



这项工作大多非常好,但有时结果接缝不正确。

例如:查询单词'的位置网页上的财务'(标题,而非链接): http://www.gmtmag.com/en/ finance.php 导致'Left'值不正确。
这取决于浏览器的宽度,但左边的位置应该是上述链接'Innovations'附近的位置。但我的位置完全不同(左侧更多)。它的接缝类似于左侧的图片没有被考虑在内。

如何确定与元素可见相同的坐标?
非常感谢!
托马斯

 htmlOffsetParent = htmlOffsetParent.offsetParent;
}

class MyPosition
{
     public Int32 AbsoluteTop;
     public Int32 AbsoluteLeft;
}

This work mostly very well, but sometime the result seams to be incorrect.

Example: Query for position of the word 'Finance' (title, not link) on Web Page: http://www.gmtmag.com/en/finance.php results in incorrect 'Left' value.
It depends on browser width, but the position left should be something near the above link 'Innovations'. But i get completely different position (more to the left side). It seams like the picture on the left side isn't taken into account.

How can i determine coordinates that results the same as the elements are visible ?

Many thanks !
Thomas

推荐答案

我正在努力实现与您相似的结果。如果你看一下这个msdn主题: http:/ /social.msdn.microsoft.com/forums/en-US/ieextensiondevelopment/thread/d96aa973-5847-41f4-adfa-fa00d444bc81/ 他们建议您使用IHTMLElement2 :: getBoundingClientRect [虽然,当我使用它时,它只返回0 - 可能是我平台的问题 - 谁知道!]。为了克服帧的问题,他们建议你使用IDiplayService :: TransformPoint()。他们有步骤告诉你exaclty如何继续。最后,我建议您使用ClientToScreen()将带有参考的点转换为屏幕。
I'm trying to achieve similar result as you are. If you look at this msdn thread: http://social.msdn.microsoft.com/forums/en-US/ieextensiondevelopment/thread/d96aa973-5847-41f4-adfa-fa00d444bc81/  they suggest you use IHTMLElement2::getBoundingClientRect [Although, when I used it, it only returned 0 - may be the problem with my platform-who knows!]. To overcome the problem of frames they suggest you use IDiplayService::TransformPoint(). They have steps telling you exaclty how to proceed. In the end, I suggest you use  ClientToScreen() to convert the point with refrence to the screen.
祝你好运!

Good Luck!


这篇关于mshtml.IHTMLElement的位置给出了意想不到的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆