禁止WebBrowser弹出网页对话框

来源:互联网 发布:软件开发成本 人月 编辑:程序博客网 时间:2024/05/06 20:13
 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    wb1: TWebBrowser;
    procedure FormCreate(Sender: TObject);
  private
    procedure WMActivate(var Msg: TWMActivate);message WM_ACTIVATE;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure  TForm1.WMActivate(var   Msg:   TWMActivate);
var
    S:String;
    wnd:HWND;
    I:Integer;
begin
  If Msg.Active=0 then
  begin
    wnd := Msg.ActiveWindow;
    I := GetWindowTextLength(wnd);
    SetLength(S,I+1);
    //the   text   of   the   specified   window 's   title   bar
    GetWindowText(Wnd, PChar(S),I+1);
    If Pos( '来自网页的消息', S) > 0 then
    Sendmessage(wnd,WM_CLOSE,0,0);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  wb1.Navigate('file://C:\Documents and Settings\Administrator\桌面\index.htm');
end;

end.

 

还有另一种方法,但是能力有限,怎么也看不懂。

IDocHostShowUI接口

http://blog.sina.com.cn/s/blog_4b3906920100npup.html