Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#2

Re: Webbrowser Scrollbalken sichtbar?

  Alt 19. Mär 2008, 19:44
Hallo,

Ich habe mal eine Funktion WB_GetScrollbarVisibility geschrieben.
Funktioniert auch, wenn zu einem lokales Verzeichnis navigiert wird.

Delphi-Quellcode:
function GetWBLV(WBHandle: HWND): HWND;
// Get SysListView32 Child from the Webbrowser Control
var
  WND: HWND;
begin
  Result := 0;
  Wnd := GetNextWindow(WBHandle, GW_CHILD);
  while (Result = 0) and (WND <> 0) do
  begin
    Result := FindWindowEx(Wnd, 0, 'SysListView32', nil);
    Wnd := GetNextWindow(Wnd, GW_CHILD)
  end;
end;

{ ************************************************************************* }
// Check if the horizontal / vertical Scrollbars are visible

procedure WB_GetScrollbarVisibility(WB: TWebbrowser; var HScroll, VScroll: Boolean);
var
  WndLV: HWND;
  IDoc: IHTMLDocument2;
begin
  VScroll := False;
  HScroll := False;
  WndLV := GetWBLV(WB.Handle);
  if WndLV = 0 then
  begin
    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
        VScroll := WB.OleObject.Document.body.ScrollHeight > WB.OleObject.Document.Body.ClientHeight;
        HScroll := (WB.OleObject.Document.body.ScrollWidth > WB.OleObject.Document.Body.ClientWidth);
      end;
    end;
  end else
  begin
    // if the WB is in "ListView" mode:
    VScroll := ((GetWindowLong(WndLV, GWL_STYLE) and WS_VSCROLL) <> 0);
    HScroll := ((GetWindowLong(WndLV, GWL_STYLE) and WS_HSCROLL) <> 0)
  end;
end;

procedure TfrmMyBrowser.GetScrollbarVisiblity1Click(Sender: TObject);
var
  VScroll, HScroll: Boolean;
const
  bYesNo: array[Boolean] of string = ('No', 'Yes');
begin
  WB_GetScrollbarVisibility(GetCurrentWB, HScroll, VScroll);
  ShowMessage('Vertical ScrollBar Visible: ' + bYesNo[VScroll] + #13#10 +
    'Horizontal ScrollBar Visible: ' + bYesNo[HScroll]);
end;
Thomas
  Mit Zitat antworten Zitat