2004. november 1., hétfő

How to invoke the Find dialog in a TWebBrowser


Problem/Question/Abstract:

How do I invoke the Find, Option or View Source options?

Answer:

Here's a code sample for invoking the Find dialog:

{ ... }
const
  HTMLID_FIND = 1;
  HTMLID_VIEWSOURCE = 2;
  HTMLID_OPTIONS = 3;
  { ... }

procedure TForm1.FindIE;
const
  CGID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
var
  CmdTarget: IOleCommandTarget;
  vaIn, vaOut: OleVariant;
  PtrGUID: PGUID;
begin
  New(PtrGUID);
  PtrGUID^ := CGID_WebBrowser;
  if WebBrowser1.Document <> nil then
  try
    WebBrowser1.Document.QueryInterface(IOleCommandTarget, CmdTarget);
    if CmdTarget <> nil then
    try
      CmdTarget.Exec(PtrGUID, HTMLID_FIND, 0, vaIn, vaOut);
    finally
      CmdTarget._Release;
    end;
  except
    {Nothing}
  end;
  Dispose(PtrGUID);
end;

Nincsenek megjegyzések:

Megjegyzés küldése