博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法
阅读量:4149 次
发布时间:2019-05-25

本文共 2020 字,大约阅读时间需要 6 分钟。

   刚有一段时间没做博客了,今天刚好有人问了这个问题,而自己以前也弄过,于是这里有了一篇新的博文。

关于改造WebBrowser控件的一些技巧,大家可以参考MSDN或者蒋晟写的一个东西,里面有讲的很详细的,今天我就说一下这个alter对话框的修改和过滤的方法:

很简单,只要咱们继承IDocHostShowUI这个接口,实现里面的ShowMessage方法就行了。

废话不多说,代码在这里:

 

DelphiCode:
unit Unit2;interfaceuses  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;  TForm2 = class(TForm)    WebBrowser1: TWebBrowser;    procedure FormCreate(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;var  Form2: TForm2;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),'不得闲测试',65);  Result := S_OK;end;procedure TForm2.FormCreate(Sender: TObject);begin  self.WebBrowser1.Navigate(Application.ExeName + '/../test.htm');end;end.

转载地址:http://rrsti.baihongyu.com/

你可能感兴趣的文章
[LeetCode]Best Time to Buy and Sell Stock
查看>>
[LeetCode]Best Time to Buy and Sell Stock II
查看>>
[LeetCode]Best Time to Buy and Sell Stock III
查看>>
[LeetCode]Binary Tree Inorder Traversal
查看>>
[LeetCode]Binary Tree Level Order Traversal
查看>>
[LeetCode]Climbing Stairs
查看>>
[LeetCode]Combination Sum II
查看>>
[LeetCode]Combinations
查看>>
[LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
查看>>
[LeetCode]Convert Sorted Array to Binary Search Tree
查看>>
[LeetCode]Longest Valid Parentheses
查看>>
[LeetCode]Maximal Rectangle
查看>>
[LeetCode]Maximum Subarray
查看>>
[LeetCode]Median of Two Sorted Arrays
查看>>
[LeetCode]Merge Intervals
查看>>
[LeetCode]Merge k Sorted Lists
查看>>
[LeetCode]Merge Sorted Array
查看>>
[LeetCode]Merge Two Sorted Lists
查看>>
[LeetCode]Minimum Depth of Binary Tree
查看>>
[LeetCode]Minimum Path Sum
查看>>