⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 delphi老牌的浏览器控件
💻 PAS
字号:
//*************************************************************
//                    EmbeddedWB - MSHTML Events              *
//                                                            *
//                            by                              *
//                     Thomas Stutz (smot)                    *
//                     smot777@yahoo.com                      *
//                                                            *
//     Documentation and updated versions:                    *
//               http://www.bsalsa.com                        *
//*************************************************************

{*******************************************************************************}
{LICENSE:
THIS SOFTWARE IS PROVIDED TO YOU "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED INCLUDING BUT NOT LIMITED TO THE APPLIED
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
YOU ASSUME THE ENTIRE RISK AS TO THE ACCURACY AND THE USE OF THE SOFTWARE
AND ALL OTHER RISK ARISING OUT OF THE USE OR PERFORMANCE OF THIS SOFTWARE
AND DOCUMENTATION. [YOUR NAME] DOES NOT WARRANT THAT THE SOFTWARE IS ERROR-FREE
OR WILL OPERATE WITHOUT INTERRUPTION. THE SOFTWARE IS NOT DESIGNED, INTENDED
OR LICENSED FOR USE IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE CONTROLS,
INCLUDING WITHOUT LIMITATION, THE DESIGN, CONSTRUCTION, MAINTENANCE OR
OPERATION OF NUCLEAR FACILITIES, AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS,
AIR TRAFFIC CONTROL, AND LIFE SUPPORT OR WEAPONS SYSTEMS. VSOFT SPECIFICALLY
DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR SUCH PURPOSE.

You may use, change or modify the demo under 4 conditions:
1. In your website, add a link to "http://www.bsalsa.com"
2. In your application, add credits to "Embedded Web Browser"
3. Mail me  (bsalsa@bsalsa.com) any code change in the unit
   for the benefit of the other users.
4. Please,  consider donation in our web site!
{*******************************************************************************}

unit Unit1;

interface

uses
  Windows, Messages, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, MSHTMLEvents, SHDocVw_EWB, EwbCore, EmbeddedWB,
  ExtCtrls;

type
  TForm1 = class(TForm)
    EmbeddedWB1: TEmbeddedWB;
    Panel1: TPanel;
    Button1: TButton;
    Label1: TLabel;
    Memo1: TMemo;
    procedure EmbeddedWB1BeforeNavigate2(ASender: TObject;
      const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
      Headers: OleVariant; var Cancel: WordBool);
    procedure EmbeddedWB1DownloadComplete(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
     function DocOnClick(Sender: TObject): WordBool;
     function DocSelectStart(Sender: TObject): WordBool;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
 MSHTML;

function TForm1.DocOnClick(Sender: TObject): WordBool;
var
  SrcElement: IHTMLElement;
  Doc: IHTMLDocument2;
begin
  Doc :=  TMSHTMLHTMLDocumentEvents(Sender).Source as IHTMLDocument2;
  if Doc <> nil then
  begin
    SrcElement := Doc.parentWindow.event.srcElement;
    // now you can do what you want with srcelement, like:
    Memo1.Text := SrcElement.innerhtml;
    Result := True;
  end;
end;

function TForm1.DocSelectStart(Sender: TObject): WordBool;
var
  Doc: IHTMLDocument2;
begin
  Doc :=  TMSHTMLHTMLDocumentEvents(Sender).Source as IHTMLDocument2;
  if Doc <> nil then
  begin
    Result := False;
    Caption := 'Selecting disabled!';
  end;
end;


procedure TForm1.EmbeddedWB1BeforeNavigate2(ASender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
var
  FSinkComponent: TMSHTMLHTMLDocumentEvents;
begin
  FSinkComponent := TEmbeddedWB(ASender).SinkComponent;
  if Assigned(FSinkComponent) then
    FSinkComponent.Disconnect;
end;

procedure TForm1.EmbeddedWB1DownloadComplete(Sender: TObject);
var
   FSinkComponent: TMSHTMLHTMLDocumentEvents;
   EWB : TEmbeddedWB;
   Document: IHTMLDocument2;
begin
   EWB := Sender as TEmbeddedWB;
   if Assigned(EWB.Document) then
   begin
     if Succeeded(EWB.Document.QueryInterface(IID_IHTMLDocument2, Document)) then
     begin
       FSinkComponent := EWB.SinkComponent;
       FSinkComponent.onselectstart := DocSelectStart;
       FSinkComponent.OnClick := DocOnClick;
       FSinkComponent.Connect(Document);
     end;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EmbeddedWB1.Go('http://www.bsalsa.com/support.html');
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -