There is finally a way to get the scroll bar position of a control that has a scroll bar (such as an Edit). Here is a working script that demonstrates this. It monitors the focused control in the active window and displays a tooltip to indicate the position of the vertical scroll bar (horizontal is also possible).
Code:
#Persistent
SetTimer, WatchScrollBar, 100
return
WatchScrollBar:
ActiveWindow := WinExist("A")
if not ActiveWindow ; No active window.
return
ControlGetFocus, FocusedControl, ahk_id %ActiveWindow%
if not FocusedControl
return
; Display the vertical scroll bar's position in a ToolTip:
ChildHWND := GetChildHWND(ActiveWindow, FocusedControl)
; Last param is 1 for SB_VERT, 0 for SB_HORZ:
Pos := DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)
ToolTip %Pos%
return
GetChildHWND(ParentHWND, ChildClassNN)
{
WinGetPos, ParentX, ParentY,,, ahk_id %ParentHWND%
if ParentX =
return ; Parent window not found (possibly due to DetectHiddenWindows).
ControlGetPos, ChildX, ChildY,,, %ChildClassNN%, ahk_id %ParentHWND%
if ChildX =
return ; Child window not found, so return a blank value.
; Convert child coordinates -- which are relative to its parent's upper left
; corner -- to absolute/screen coordinates for use with WindowFromPoint().
; The following INTENTIONALLY passes too many args to the function because
; each arg is 32-bit, which allows the function to automatically combine
; them into one 64-bit arg (namely the POINT struct):
return DllCall("WindowFromPoint", "int", ChildX + ParentX, "int", ChildY + ParentY)
}