码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi中WebBrowser拦截网页Alert对话框消息(转)

时间:2016-04-03 13:15:47      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:

interface 
   
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  Dialogs, OleCtrls, SHDocVw, ActiveX;  
   
type 
  IDocHostShowUI = interface(IUnknown)  
    [{c4d244b0-d43e-11cf-893b-00aa00bdce1a}]  
    function ShowMessage(hwnd: THandle; lpstrText: POLESTR; lpstrCaption: POLESTR;dwType: longint; lpstrHelpfile: POLESTR; dwHelpContext: longint;var plResult: LRESULT): HRESULT; stdcall;  
    function ShowHelp(hwnd: THandle; pszHelpfile: POLESTR; uCommand: integer;dwData: longint; ptMouse: TPoint; var pDispatchObjectHit: IDispatch): HRESULT; stdcall;  
  end;  
   
  TWebBrowser = class(SHDocVw.TWebBrowser,IDocHostShowUI)  
  protected 
    function ShowMessage(hwnd: THandle; lpstrText: POLESTR; lpstrCaption: POLESTR;dwType: longint; lpstrHelpfile: POLESTR; dwHelpContext: longint;var plResult: LRESULT): HRESULT; stdcall;  
    function ShowHelp(hwnd: THandle; pszHelpfile: POLESTR; uCommand: integer;dwData: longint; ptMouse: TPoint; var pDispatchObjectHit: IDispatch): HRESULT; stdcall;  
  end;  
   
   
type 
  TForm1 = class(TForm)  
    WebBrowser1: TWebBrowser;  
    procedure FormCreate(Sender: TObject);  
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end;  
   
var 
  Form1: TForm1;  
   
implementation 
   
{$R *.dfm} 
   
{ TWebBrowser } 
   
function TWebBrowser.ShowHelp(hwnd: THandle; pszHelpfile: POLESTR; uCommand,  
  dwData: Integer; ptMouse: TPoint; var pDispatchObjectHit: IDispatch): HRESULT;  
begin 
  Result := S_FALSE;  
end;  
   
function TWebBrowser.ShowMessage(hwnd: THandle; lpstrText,  
  lpstrCaption: POLESTR; dwType: Integer; lpstrHelpfile: POLESTR;  
  dwHelpContext: Integer; var plResult: LRESULT): HRESULT;  
begin 
  //plResult := MessageBoxW(hwnd,PWChar(lpstrText),Title,64);//这里屏蔽了alert  
  Result := S_OK;  
end;  
   
procedure TForm1.FormCreate(Sender: TObject);  
begin 
  WebBrowser1.Navigate(E:/alert.htm);  
end;  
   
end.

方法是实现了IDocHostShowUI接口,重写了弹出消息的方法。

Delphi中WebBrowser拦截网页Alert对话框消息(转)

标签:

原文地址:http://www.cnblogs.com/delphi7456/p/5349619.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!