• 学习 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.
    
  • 相关阅读:
    光盘和U盘
    解决时间同步
    僵尸进程 和 孤儿进程
    Centos虚拟机设置网络模式
    常用CDN 和 后台管理模板
    微信小程序wxs如何使用
    kubernetes/client-go--使用 Clientset 获取 Kubernetes 资源对象
    samplecontroller
    volcano
    DNS欺骗
  • 原文地址:https://www.cnblogs.com/del/p/1319318.html
Copyright © 2020-2023  润新知