如何判断Web浏览器控件上是否显示滚动条 [英] How to tell if scroll bars are visible on the web browser control

查看:115
本文介绍了如何判断Web浏览器控件上是否显示滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio 2012 MFC应用程序,它有一个对话框,我在其中托管IE WebBrowser控件。

I have a Visual Studio 2012 MFC app that has a dialog where I host the IE WebBrowser control.

在我调用Navigate后,我需要知道是垂直还是出现水平滚动条,垂直条的宽度和水平条的高度(实际上我认为系统设置对该测量有效)。我尝试了以下内容:

After I call Navigate, I need to know if the vertical or horizontal scroll bars appear and how wide the vertical bar is and the height of the horizontal bar (actually I think the system setting is valid for that measurement). I have tried the following:

1。)从对话框开始,调用GetWindowLong获取GWL_STYLE并测试WS_HSCROLL和WS_VSCROLL。如果不存在则获取子窗口并执行相同操作。我循环这样做,直到没有更多的子窗口。当我看到滚动条时,样式甚至不会出现
。我在调试时使用了间谍,以确保我访问了每个孩子,包括"Shell Embedding","Shell DocObject View"等。和"internet Explorer_Server"; (这是我的整个窗口结构)。

1.) Start at the dialog and call GetWindowLong to get GWL_STYLE and test for WS_HSCROLL and WS_VSCROLL. If not present get the child window and do the same. I do this in a loop until there are no more child windows. The style is not present anywhere even when I see the scroll bars. I have used spy as I debugged to ensure I visitied every child including the "Shell Embedding", "Shell DocObject View" and "internet Explorer_Server" (that's my entire window structure).

2。)我从浏览器控件获取文档正文,然后使用get_parentWindow获取它的父窗口。然后我从该窗口对象获取了IHTMLWindow7接口。我得到了window对象的innerWidth和outerWidth。我希望两者之间的
差异会告诉我滚动条是否存在(以及它有多宽)。无论我是否看到垂直滚动条,差异总是14。巧合的是(?)滚动条的宽度/高度为14。

2.) I obtained the document body from the browser control and then the parent window of it using get_parentWindow. I then obtained the IHTMLWindow7 interface from that window object. I get the innerWidth and outerWidth of the window object. I am hoping the difference between the two would tell me the scroll bar is present (and how wide it is). The difference is always 14 regardless of whether I see the vertical scroll bar or not. Coincidentally (?) the width/height of a scroll bar is 14.

3。)我从正文中获取了IHTMLElement2接口并调用了get_scrollWidth和get_scrollHeight。然后我将scrollWidth与从IHTMLWindow7接口获得的innerWidth进行了比较。这看起来很有希望。随着我缩小窗口,我可以
看到两个值收敛。当innerWidth小于scrollWidth时,将出现垂直滚动条。但是,一旦出现垂直滚动条并调整窗口大小以使其变宽,则innerWidth会大于scrollWidth,但滚动
栏仍然可见。直到内部宽度超过scrollWidth时才会这样做......看起来是滚动条本身的宽度(以像素为单位) - 14.滚动条的外观和消失之间的差距使这种方法成为
我的目的无法使用ul。

3.) I obtained the IHTMLElement2 interface from the body and called get_scrollWidth and get_scrollHeight. Then I compared the scrollWidth to the innerWidth obtained from the IHTMLWindow7 interface. This looked quite promising. As I narrow my window I can see the two values converging. When innerWidth becomes less than scrollWidth the vertical scroll bar appears. However, once the vertical scroll bar appears and I resize the window to make it wider, the innerWidth gets larger than the scrollWidth but the scroll bar remains visible. It does so until just about when the innerWidth exceeds the scrollWidth by ... what appears to be the width in pixels of the scroll bar itself - 14. This gap between the appearance and disappearance of the scroll bar makes this approach unusable ul for my purposes.

如何判断滚动条是否可见?一旦我知道它们可见,我认为宽度/高度的系统信息总是准确的。

How can I tell if either scroll bar is visible? I assume the system info on width/height will always be accurate once I know they are visible.

R.D。 Holland

R.D. Holland

推荐答案

WBC有一个滚动条属性。

the WBC has a scrollbars property.

网页内容中的滚动条外观由包含节点的显示和溢出样式属性以及网页的documentMode(和documentType声明)确定。

scrollbar appearance in web page content is determined by the display and overflow style properties of the containing node and the documentMode (and documentType declaration) of your web page.

scrollHeight / scrollWidth是您的网页正确编码时需要查询的节点属性。

scrollHeight/scrollWidth is the node property that you need to query if your web page is correctly coded.

首先使用符合标准的标记架构在Web浏览器中调试页面标记。使用feature-control-browser-emulation确保您的托管WBC能够在已安装的IE浏览器版本的Edge模式下呈现。

Debug your page markup in a web browser first, using a standards compliant markup schema. Use the feature-control-browser-emulation to ensure your hosted WBC is capable of rendering in the Edge mode of the installed IE Browser version.

此论坛是关于html,css和使用MSIE浏览器的网站开发人员的脚本。将关于WBC的问题发布到IE扩展开发论坛。

this forum is for questions about html, css and scripting for website developers using MSIE browsers. Post questions about the WBC to the IE Extension Development forum.

问候。


这篇关于如何判断Web浏览器控件上是否显示滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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