uses
MSHTML;
// Webbrowser Scrollbar X,Y Position ermitteln
function WB_GetScrollPosition(WB: TWebbrowser;
var P: TPoint): Boolean;
// Scrollbar X,Y Position der ListView ermitteln
function WB_GetLVScrollPosition(WB: TWebbrowser;
var P: TPoint): Boolean;
var
lpsi: TScrollInfo;
WND, WndLV: HWND;
begin
Result := False;
FillChar(lpsi, SizeOf(lpsi), 0);
with lpsi
do
begin
cbSize := SizeOf(lpsi);
fMask := SIF_ALL;
end;
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
begin
if GetScrollInfo(wnd, SB_VERT, lpsi)
then
begin
P.Y := lpsi.nPos;
if GetScrollInfo(WND, SB_HORZ, lpsi)
then
begin
P.X := lpsi.nPos;
Result := True;
end;
end;
end;
end;
// Scrollbar X,Y Position des HTML Documents ermitteln
function WB_GetDOCScrollPosition(WB: TWebbrowser;
var P: TPoint): Boolean;
var
IDoc: IHTMLDocument2;
IDoc3: IHTMLDocument3;
IElement: IHTMLElement;
begin
P := 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
P.Y := IHTMLDocument2(IDoc).Body.getAttribute('
ScrollTop', 0)
else
P.Y := Variant(IDoc).DocumentElement.scrollTop;
if Assigned(IElement)
and (Variant(IDoc).DocumentElement.scrollLeft = 0)
then
P.X := IHTMLDocument2(IDoc).Body.getAttribute('
ScrollLeft', 0)
else
P.X := Variant(IDoc).DocumentElement.scrollLeft
end;
Result := (P.X <> -1)
and (P.Y <> -1)
end;
end;
begin
Result := False;
if not WB_GetDOCScrollPosition(WB, P)
then
Result := WB_GetLVScrollPosition(WB, P);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// WebBrowser1.Navigate('file://c:\'); // zu einer lokalen Datei navigieren
WebBrowser1.Navigate('
www.google.com');
end;
// test:
procedure TForm1.Button2Click(Sender: TObject);
var
P: TPoint;
begin
if WB_GetScrollPosition(Webbrowser1, P)
then
ShowMessage(Format('
X: %d, Y: %d', [P.X, P.Y]));
end;