// Webbrowser Scrollbar X,Y Position ermitteln
function WB_GetScrollPosition(WB: TWebBrowser;
var ScrollPos: TPoint): Boolean;
// Scrollbar X,Y Position der ListView ermitteln
function WB_GetLVScrollPosition(WB: TWebBrowser;
var ScrollPos: TPoint): Boolean;
var
lpsi: TScrollInfo;
WND, WndLV: HWND;
begin
Result := False;
// SysListView32 Child vom TWebBrowser suchen
WndLV := 0;
Wnd := GetNextWindow(WB.Handle, GW_CHILD);
while (WndLV = 0)
and (WND <> 0)
do
begin
WndLV := FindWindowEx(Wnd, 0, '
SysListView32',
nil);
Wnd := GetNextWindow(Wnd, GW_CHILD)
end;
if WndLV <> 0
then // SysListView32 gefunden
begin
// TScrollInfo initialisieren
FillChar(lpsi, SizeOf(lpsi), 0);
with lpsi
do
begin
cbSize := SizeOf(lpsi);
fMask := SIF_POS;
end;
// ScrollInfos der vertikalen ScrollBar ermitteln
if GetScrollInfo(WndLV, SB_VERT, lpsi)
then
begin
ScrollPos.Y := lpsi.nPos;
// ScrollInfos der horizontalen ScrollBar ermitteln
if GetScrollInfo(WndLV, SB_HORZ, lpsi)
then
begin
ScrollPos.X := lpsi.nPos;
Result := True;
end;
end;
end;
end;
// Scrollbar X,Y Position des HTML Documents ermitteln
function WB_GetDOCScrollPosition(WB: TWebBrowser;
var ScrollPos: TPoint): Boolean;
var
IDoc: IHTMLDocument2;
IDoc3: IHTMLDocument3;
IElement: IHTMLElement;
begin
ScrollPos := Point(-1, -1);
Result := False;
if Assigned(WB.Document)
and (Succeeded(WB.Document.QueryInterface(IHTMLDocument2, IDoc)))
then
begin
IDoc := WB.Document
as IHTMLDocument2;
if Assigned(IDoc)
and Assigned((IHTMLDocument2(IDoc).Body))
then
begin
if (IDoc.QueryInterface(IHTMLDocument3, IDoc3) = S_OK)
then
if Assigned(IDoc3)
then
IElement := IDoc3.get_documentElement;
if (Assigned(IElement))
and (Variant(IDoc).DocumentElement.scrollTop = 0)
then
ScrollPos.Y := IHTMLDocument2(IDoc).Body.getAttribute('
ScrollTop', 0)
else
ScrollPos.Y := Variant(IDoc).DocumentElement.scrollTop;
if Assigned(IElement)
and (Variant(IDoc).DocumentElement.scrollLeft = 0)
then
ScrollPos.X := IHTMLDocument2(IDoc).Body.getAttribute('
ScrollLeft', 0)
else
ScrollPos.X := Variant(IDoc).DocumentElement.scrollLeft
end;
Result := (ScrollPos.X <> -1)
and (ScrollPos.Y <> -1)
end;
end;
begin
Result := WB_GetDOCScrollPosition(WB, ScrollPos);
if not Result
then
Result := WB_GetLVScrollPosition(WB, ScrollPos);
end;