Thank you
Ok, my situation:
I've got 2 Scripts, the first script is my main program, it contains a normal Internet Explorer control, the second script is this:
Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
a::
;---------------------------------------------------------------------------------------------------------------
;
; CONFIGURATION
;
UPDATE_RATE = 10 ; milliseconds
SENSITIVITY = 0.5
INERTIA = 0.95
;
; WIN32 DEFINES
;
; SetWinEventHook Flags
WINEVENT_OUTOFCONTEXT = 0x0000
; Events
EVENT_SYSTEM_SCROLLINGSTART = 0x0012
EVENT_SYSTEM_SCROLLINGEND = 0x0013
; Scrollbar Constants
SB_HORZ = 0
SB_VERT = 1
;
; INITIALIZATION
;
SpeedA := 1 - SENSITIVITY
; Register callback proc.
cbOnScrollEvent := RegisterCallback("OnScrollEvent")
; IE support init.
WM_HTML_GETOBJECT := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
COM_CoInitialize()
;Get main window's handle
WinGet, hMainGUIHwnd, ID, ahk_class AutoHotkeyGUI
ControlGet, hEditControlHwnd, Hwnd, , Internet Explorer_Server1, ahk_class AutoHotkeyGUI
hHwnd := hMainGUIHwnd
Scroll_Type := "scrollbarHThumb"
info := GetAbstractScrollInfo(hWnd,Scroll_type)
Loop,
{
ifnotexist,dom.txt
continue
fileread,dom,dom.txt
Break
}
GetDeepestScrollElement(dom)
Return
;---------------------------------------------------------------------------------------------------------------
;
; FUNCTIONS - Standard Windows Scrollbars
;
GetScrollInfo(hwnd, fnBar, ByRef nPos=0, ByRef nTrackPos=0, ByRef nMin=0, ByRef nMax=0, ByRef nPage=0)
{
WinGet, Style, Style, ahk_id %hwnd%
if !(Style & (fnBar ? 0x200000 : 0x100000))
return false ; Fix for some controls which report {min:0,max:100} even though scroll bar doesn't exist.
VarSetCapacity(si, 28, 0) ; SCROLLINFO si
NumPut(28 , si, 0) ; si.cbSize := sizeof(SCROLLINFO)
NumPut(0x17, si, 4) ; si.fMask := SIF_ALL
if ! DllCall("GetScrollInfo", "uint", hwnd, "int", fnBar, "uint", &si)
return false
nPos := NumGet(si, 20)
nTrackPos := NumGet(si, 24)
nMin := NumGet(si, 8)
nMax := NumGet(si, 12)
nPage := NumGet(si, 16)
return true
}
SetScrollPos(hwnd, fnBar, nPos)
{
VarSetCapacity(si, 28, 0) ; SCROLLINFO si
NumPut(28 , si, 0) ; si.cbSize := sizeof(SCROLLINFO)
NumPut(0x4 , si, 4) ; si.fMask := SIF_POS
NumPut(nPos, si, 20) ; si.nPos := nPos
; Use SetScrollInfo first because it supports 32-bit positions.
; If an application supports positions < 0 or > 65535, it most likely
; ignores WM_#SCROLL's wParam and uses GetScrollPos or GetScrollInfo
; to get the actual scroll position.
DllCall("SetScrollInfo", "uint", hwnd, "int", fnBar, "uint", &si, "int", 0)
; WM_HSCROLL or WM_VSCROLL must be sent for the window to update it's contents.
msg := (fnBar=0) ? 0x114 : 0x115
wParam := 4 ; SB_THUMBPOSITION
| ((nPos&0xFFFF)<<16)
SendMessage, msg, wParam,,, ahk_id %hwnd%
return (ErrorLevel != "FAIL")
}
;
; ABSTRACT FUNCTIONS - for both standard Windows scrollbar and IE scrollbar support.
;
GetAbstractScrollInfo(Container, Type, ByRef Pos=0, ByRef Min=0, ByRef Max=0)
{
if !Container
return false
if Type in 0,1 ; SB_HORZ,SB_VERT
return GetScrollInfo(Container, Type, Pos, track_pos, Min, Max)
if Type = scrollbarHThumb
Pos:=COM_Invoke(Container,"scrollLeft"), Max:=COM_Invoke(Container,"scrollWidth"), Min:=0
else if Type = scrollbarVThumb
Pos:=COM_Invoke(Container,"scrollTop"), Max:=COM_Invoke(Container,"scrollHeight"), Min:=0
return Pos!=""
}
SetAbstractScrollPos(Container, Type, Pos)
{
if !Container
return false
if Type in 0,1 ; SB_HORZ,SB_VERT
return SetScrollPos(Container, Type, Pos)
; TODO: determine success or failure for assignment.
if Type = scrollbarHThumb
return true, COM_Invoke(Container,"scrollLeft=",Pos)
else if Type = scrollbarVThumb
return true, COM_Invoke(Container,"scrollTop=",Pos)
return false
}
;
; IE FUNCTIONS & SUBROUTINES
;
GetDeepestScrollElement(pWin, x, y, ByRef pElement, ByRef pElementWin)
{
; AddRef so we don't release pWin below. (Caller may still need it.)
COM_AddRef(win:=pWin)
Loop {
if (!win)
break ; Error
if !(doc:=COM_Invoke(win,"document"))
break ; Error
if !(element:=COM_Invoke(doc,"elementFromPoint",x-COM_Invoke(win,"screenLeft"),y-COM_Invoke(win,"screenTop")))
break ; Error
if (tag:=COM_Invoke(element,"tagName")) != "FRAME"
{ ; return element.isScrollable ? element : frame.body
scrollHeight:=COM_Invoke(element,"scrollHeight"), clientHeight:=COM_Invoke(element,"clientHeight")
if !(clientHeight && clientHeight < scrollHeight)
COM_Release(element), element:=COM_Invoke(doc,"body")
break
}
COM_Release(doc), doc:=0, COM_Release(win), win:=0
if !(win:=COM_Invoke(element,"contentWindow"))
{
COM_Release(element), element:=0
break ; Error
}
}
if doc
COM_Release(doc), doc:=0
if (win && !element)
COM_Release(win), win:=0
pElement := element
pElementWin := win
return pElement
}
GetIEDocumentAtMouse:
MouseGetPos,,,, hIESvr, 2
WinGetClass, class, ahk_id %hIESvr%
if (!hIESvr or class != "Internet Explorer_Server")
{ ; Try again with alternate method (for "Microsoft Document Explorer" support.)
MouseGetPos,,,, hIESvr, 3
WinGetClass, class, ahk_id %hIESvr%
if (!hIESvr or class != "Internet Explorer_Server")
return
}
SendMessage, WM_HTML_GETOBJECT,,,, ahk_id %hIESvr%
lResult := ErrorLevel
DllCall("oleacc\ObjectFromLresult", "uint", lResult
, "uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}")
, "int", 0, "uint*", pDoc)
return
GetActiveScrollElement(win)
{
if !win
return 0
COM_AddRef(win) ; caller is responsible for releasing win
Loop {
if (!win)
break ; Error
if !(doc:=COM_Invoke(win,"document")), COM_Release(win),win:=0
break ; Error
if !(element:=COM_Invoke(doc,"activeElement"))
break ; Error
if (tag:=COM_Invoke(element,"tagName")) != "FRAME"
{ ; return element.isScrollable ? element : frame.body
scrollHeight:=COM_Invoke(element,"scrollHeight"), clientHeight:=COM_Invoke(element,"clientHeight")
if !(clientHeight && clientHeight < scrollHeight)
COM_Release(element), element:=COM_Invoke(doc,"body")
break
}
COM_Release(doc),doc:=0
if !(win:=COM_Invoke(element,"contentWindow"))
{
COM_Release(element), element:=0
break ; Error
}
}
doc ? COM_Release(doc) . doc:=0 : ""
return element
}
#include, resources\COM.ahk
(got an errormessage

Too few parameters passed to function)
In my first script i'd insert this, before the first return:
Code:
dom := COM_Invoke(pwb,"Document.parentWindow" )
filedelete,dom.txt
fileappend,%dom%,dom.txt
The Dom Var contains some numbers ...
Could you please give me an example, how i could use your function (with an IE Control)?
I want to set the scroll position of the IE Control.
Thanks!
Greets,
DHMH