学習メッセージ(11):TWMmoouse構造に関するマウスメッセージをテストする

5310 ワード

TWMmouseと一致するメッセージ構造は次のとおりです.


TWMLButtonDblClk { }

TWMLButtonDown   { }

TWMLButtonUp     { }

TWMMButtonDblClk { }

TWMMButtonDown   { }

TWMMButtonUp     { }

TWMMouseMove     { }

TWMRButtonDblClk { }

TWMRButtonDown   { }

TWMRButtonUp     { }


 
   

コードファイル:


unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;



type

  TForm1 = class(TForm)

    Memo1: TMemo;

    CheckBox1: TCheckBox;

    Button1: TButton;

    procedure FormCreate(Sender: TObject);

    procedure Button1Click(Sender: TObject);

  protected

    procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;

    procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;

    procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;

    procedure WMMButtonDblClk(var Message: TWMMButtonDblClk); message WM_MBUTTONDBLCLK;

    procedure WMMButtonDown(var Message: TWMMButtonDown); message WM_MBUTTONDOWN;

    procedure WMMButtonUp(var Message: TWMMButtonUp); message WM_MBUTTONUP;

    procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;

    procedure WMRButtonDblClk(var Message: TWMRButtonDblClk); message WM_RBUTTONDBLCLK;

    procedure WMRButtonDown(var Message: TWMRButtonDown); message WM_RBUTTONDOWN;

    procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);

begin

  Memo1.Clear;

end;



procedure TForm1.FormCreate(Sender: TObject);

begin

  Memo1.Align := alLeft;

  Memo1.ScrollBars := ssVertical;

  Memo1.Clear;

  Position := poScreenCenter;

  CheckBox1.Caption := ' ';

  Button1.Caption := ' ';

end;



procedure TForm1.WMLButtonDblClk(var Message: TWMLButtonDblClk);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMLButtonDown(var Message: TWMLButtonDown);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMLButtonUp(var Message: TWMLButtonUp);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMMButtonDblClk(var Message: TWMMButtonDblClk);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMMButtonDown(var Message: TWMMButtonDown);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMMButtonUp(var Message: TWMMButtonUp);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMMouseMove(var Message: TWMMouseMove);

var

  x,y: Integer;

  s: string;

begin

  if not CheckBox1.Checked then Exit;

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMRButtonDblClk(var Message: TWMRButtonDblClk);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMRButtonDown(var Message: TWMRButtonDown);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



procedure TForm1.WMRButtonUp(var Message: TWMRButtonUp);

var

  x,y: Integer;

  s: string;

begin

  x := Message.XPos;

  y := Message.YPos;

  s := Format(' : %d,%d', [x,y]);

  Memo1.Lines.Add(s);

  Message.Result := 0;

end;



end.


 
   
フォームファイル:


object Form1: TForm1

  Left = 0

  Top = 0

  Caption = 'Form1'

  ClientHeight = 206

  ClientWidth = 321

  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 Memo1: TMemo

    Left = 8

    Top = 8

    Width = 185

    Height = 89

    Lines.Strings = (

      'Memo1')

    TabOrder = 0

  end

  object CheckBox1: TCheckBox

    Left = 199

    Top = 8

    Width = 122

    Height = 17

    Caption = 'CheckBox1'

    TabOrder = 1

  end

  object Button1: TButton

    Left = 199

    Top = 173

    Width = 75

    Height = 25

    Caption = 'Button1'

    TabOrder = 2

    OnClick = Button1Click

  end

end