学习 Message(6): 也可以直接覆盖祖先类的 WndProc 或 Dispatch 方法来响应消息


覆盖: WndProc
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  protected
    procedure WndProc(var Message: TMessage); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WndProc(var Message: TMessage);
begin
  inherited;
  if Message.Msg = WM_LBUTTONDOWN then
    ShowMessage('WndProc');
end;

end.

 
 
 
 
 

 

 
  

覆盖: Dispatch
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  public
    procedure Dispatch(var Message); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Dispatch(var Message);
begin
  inherited;
  if TMessage(Message).Msg = WM_LBUTTONDOWN then
    ShowMessage('Dispatch');
end;

end.

 
 
 
 
 

 

 
  

你可能感兴趣的:(学习 Message(6): 也可以直接覆盖祖先类的 WndProc 或 Dispatch 方法来响应消息)