学習Message(6):祖先クラスのWndProcまたはDispatchメソッドを直接上書きしてメッセージに応答することもできます.

1250 ワード

上書き: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.