zoukankan      html  css  js  c++  java
  • 学习 Message(5): 关于 TApplicationEvents.OnMessage 的第二个参数


    TApplicationEvents.OnMessage 的第二个参数 Handled 如果是 True, 表示消息已经处理过了, 到此为止.
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, AppEvnts, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Memo1: TMemo;
        ApplicationEvents1: TApplicationEvents;
        procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
      if Msg.message = WM_LBUTTONDOWN then
      begin
        Memo1.Lines.Add('OnMessage');
        Handled := False; {Handled 默认是 False, 这句可以省略}
    //    Handled := True;  {如果这样, 下面 OnMouseDown 事件将不会得到执行}
      end;
    end;
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      Memo1.Lines.Add('OnMouseDown');
    end;
    
    end.
    

    我们可以利用这个特性来屏蔽一些消息, 譬如给 TWebBrowser 屏蔽右键菜单:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OleCtrls, SHDocVw, AppEvnts;
    
    type
      TForm1 = class(TForm)
        WebBrowser1: TWebBrowser;
        ApplicationEvents1: TApplicationEvents;
        procedure FormCreate(Sender: TObject);
        procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
      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) then
      begin
        Handled := True;
      end;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      WindowState := wsMaximized;
      WebBrowser1.Align := alTop;
      WebBrowser1.Navigate('http://www.cnblogs.com/del/');
    end;
    
    end.
    
  • 相关阅读:
    四种访问权限修饰符的区别
    安全框架Shiro和Spring Security比较
    POJ 1873 The Fortified Forest 凸包 二进制枚举
    POJ 2007 Scrambled Polygon 极角排序
    POJ 1113 Wall 凸包
    hdu 2276 Kiki & Little Kiki 2 矩阵快速幂
    UVA 10689 Yet another Number Sequence 矩阵快速幂 水呀水
    UVa 10655 Contemplation! Algebra 矩阵快速幂
    直线与直线相交 直线与线段相交 线段与线段相交
    hdu 4686 Arc of Dream 自己推 矩阵快速幂
  • 原文地址:https://www.cnblogs.com/del/p/1319318.html
Copyright © 2011-2022 走看看