让IE右键失效

1 

主要演示了TApplicationEvents.OnMessage 的第二个参数 Handled 如果是 True, 表示消息已经处理过了, 到此为止.

代码如下:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    ApplicationEvents1: TApplicationEvents;
    procedure FormCreate(Sender: TObject);
    procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
  if IsChild(WebBrowser1.Handle,Msg.hwnd) and ((Msg.message=WM_RBUTTONDOWN) or (Msg.message=WM_RBUTTONDBLCLK)) then
  begin
    Handled:=true;
  end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WindowState:= wsMaximized;
  WebBrowser1.Align:=alTop;
  WebBrowser1.Navigate('http://www.baidu.com');
end;

end.

-------------------------------------------------------------

界面代码如下:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'IE'#21491#38190#22833#25928
  ClientHeight = 247
  ClientWidth = 312
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object WebBrowser1: TWebBrowser
    Left = 4
    Top = 8
    Width = 300
    Height = 201
    TabOrder = 0
    ControlData = {
      4C000000021F0000C61400000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
  object ApplicationEvents1: TApplicationEvents
    OnMessage = ApplicationEvents1Message
    Left = 24
    Top = 216
  end
end

 

posted @ 2010-02-15 16:18  猪悟能  阅读(243)  评论(0编辑  收藏  举报