From: Juergen Thuemmler on 2 Jul 2010 04:06 Hi *.*, how can I get/set the scrolling position of a browser window (internet explorer_server) in IE8? To get I tried GetScrollPos(), FlatSB_GetScrollPos() and GetScrollInfo() without any success... Juergen.
From: Mayayana on 2 Jul 2010 09:31 I don't know about that, but would it help to have the pixel offset? Document.Body.scrollTop will get you the scrolled position of the page itself in pixels. If you don't already have access to the Document you can probably use the Shell object Windows collection, but that's rather clunky. The code below will return a Document from ANY window of class Ineternet Explorer_Server (IE, HTA, pre-XP folder window, WB control, etc.) It lacks a UUID declare and needs a reference to MSHTML.tlb. Oleacc.dll is Active Accessibility, which is pre-installed post Win98 and can be installed on Win98. I think Eduardo Morcillo may have actually found this method. ObjectFromLresult is intended for use with AA, but it can apparently return an object pointer for any interface GUID. (If you look up the docs you'll see this implementation bends the intent of the function somewhat, but it works. :) Private Const SMTO_ABORTIFHUNG = &H2 Private Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, riid As UUID, ByVal wParam As Long, ppvObject As Any) As Long Private Function GetIEDoc(ByVal H1 As Long, Success As Boolean) As IHTMLDocument Dim IID_IHTMLDocument2 As UUID Dim LMsg As Long, LRes As Long, LRet As Long, H2 As Long Success = False H2 = GetIEWindow(H1) If (H2 = 0) Then Exit Function LMsg = RegisterWindowMessage("WM_HTML_GETOBJECT") LRet = SendMessageTimeout(H2, LMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, LRes) If LRes = 0 Then Exit Function With IID_IHTMLDocument2 .Data1 = &H332C4425 .Data2 = &H26CB .Data3 = &H11D0 .Data4(0) = &HB4 .Data4(1) = &H83 .Data4(2) = &H0 .Data4(3) = &HC0 .Data4(4) = &H4F .Data4(5) = &HD9 .Data4(6) = &H1 .Data4(7) = &H19 End With LRet = ObjectFromLresult(LRes, IID_IHTMLDocument2, 0, GetIEDoc) If LRet = 0 Then Success = True End Function -- -- "Juergen Thuemmler" <thue(a)removethisgmx.de> wrote in message news:e5Q701bGLHA.4956(a)TK2MSFTNGP02.phx.gbl... | Hi *.*, | | how can I get/set the scrolling position of a browser window (internet | explorer_server) in IE8? | To get I tried GetScrollPos(), FlatSB_GetScrollPos() and GetScrollInfo() | without any success... | | Juergen. | |
From: Juergen Thuemmler on 3 Jul 2010 06:46 Hi Mayayana, thanks for the hint; sounds interisting. But it is only useful for me, when I can also SET this position (I don't know whether Document.Body.scrollTop can be set...). And: Which references do I need to add to the project to do so? Juergen.
From: Mayayana on 3 Jul 2010 10:02 | thanks for the hint; sounds interisting. But it is only useful for me, when | I can also SET this position (I don't know whether | Document.Body.scrollTop can be set...). | And: Which references do I need to add to the project to do so? | Yes, you can set it. I use that method to store and restore the scroll position of a WB. The following simple VBScript demonstrates it. Put a large HTML file on the Desktop (edit path in script as necessary) then run this script as a .VBS file. Dim IE Set IE = CreateObject("InternetExplorer.Application") IE.visible = True IE.navigate2 "C:\windows\desktop\test1.html" Do While IE.ReadyState <> 4 WScript.sleep 100 Loop IE.document.Body.scrollTop = 500 WScript.sleep 2000 IE.document.Body.scrollTop = 1000 WScript.sleep 2000 IE.document.Body.scrollTop = 10 WScript.sleep 2000 IE.Quit Set IE = Nothing WScript.quit Also see scrollHeight, offsetHeight, scrollLeft, scrollWidth, etc. By using various properties you can know the total height of the page, the height of the window, the current scroll position, etc. And you can set the scroll position. You need a reference to mshtml.tlb (Microsoft HTML Object Library) to get intellisense for the IE document object model. You need a reference to shdocvw.dll (Microsoft Internet Controls) for the IE object. If you have an IE or a WebBrowser control -- those being basically the same thing -- you can reference the document object directly as IE.Document or WB.Document. If you use the Shell object Windows collection to "catch" IE you can do the same, but the LocationURL is just about the only way to tell which window is the one you want. (See my posts last week in the thread named "Multi file explorer".) Otherwise, as noted above, you can get any IE document by enumerating open windows until you get to an Internet Explorer_Server class window. (Watch out for frames and IFRAMES, though. They're each a separate browser window.) Once you have the Document object, what you can do is vast. You have access to the whole DOM, which includes large sub-objects like the Style property of each element. Pretty much anything you can code in an HTML editor can be automated in a browser window. If you declare an HTMLDocument object variable WithEvents you can also respond to those: Private Sub Doc_onmouseover() Dim El As IHTMLElement On Error Resume Next '-- always a good idea here. The element '-- may not have an ID, etc. Set El = Doc.parentWindow.event.srcElement Msgbox El.tagName & vbcrlf & El.Id & vbcrlf & El.ClassName & vbcrlf & El.Style.cssText Set El = Nothing End Sub I ran the sample script above in IE6. IE has become progressively more restrictive since IE5, in terms of security. And the local PC "zone" is now more restrictive than the Internet zone! What works in IE6 won't always work in IE7/8. But as long as you're not trying to use "unsafe" scripting/objects -- or trying to do something possibly exploitive like opening an IE instance offscreen (IE.Left = 5000) -- it should work fine. ...That gets into a whole different issue. I don't know how you're getting IE. If it's an HTA you can do pretty much whatever you want. Likewise with a WB, I think, except that there's now a security setting option in IE to disable scripting in a web browser control. Also note: The Document object is lost and replaced when the webpage changes. Again, I don't know how you're getting the browser window. If you want to always have access to the Document events you need to reassign the object variable with each IE or WB DocumentComplete event.
From: Juergen Thuemmler on 3 Jul 2010 16:10 Hi Mayayana, > Yes, you can set it. I use that method to store > and restore the scroll position of a WB. The following > simple VBScript demonstrates it. Put a large HTML > file on the Desktop (edit path in script as necessary) > then run this script as a .VBS file. </> thank you very much for your detailed response. I'll try it, but it may take some days... Juergen.
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: MSVBVM50.DLL Next: WorkBook Tab display mode of SpreadSheet control in VB 6.0 |