I have a Visual Studio 2012 MFC app that has a dialog where I host the IE WebBrowser control.
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.) 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.) 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.) 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