博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
学习 Message(11): 测试 TWMMouse 结构相关的鼠标消息
阅读量:5974 次
发布时间:2019-06-19

本文共 4723 字,大约阅读时间需要 15 分钟。

  hot3.png

和 TWMMouse 一致的消息结构有:

TWMLButtonDblClk {左键双击}TWMLButtonDown   {左键按下}TWMLButtonUp     {左键抬起}TWMMButtonDblClk {中键双击}TWMMButtonDown   {中键按下}TWMMButtonUp     {中键抬起}TWMMouseMove     {鼠标移动}TWMRButtonDblClk {右键双击}TWMRButtonDown   {右键按下}TWMRButtonUp     {右键抬起}
代码文件:

unit Unit1;interfaceuses  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  endend

转载于:https://my.oschina.net/hermer/blog/319695

你可能感兴趣的文章
Timer 和 TimerTask 例子
查看>>
Spring BOOT 集成 RabbitMq 实战操作(一)
查看>>
安装python3.5注意事项及相关命令
查看>>
进程通信之无名信号量
查看>>
并发串行调用接口
查看>>
C# 视频监控系列 序 [完]
查看>>
Mongodb3.0.5副本集搭建及spring和java连接副本集配置
查看>>
FileStream大文件复制
查看>>
TDD 的本质不是 TDD
查看>>
linux命令学习——ps
查看>>
freemark 判断list是否为空
查看>>
JS的一些扩展:String、StringBuilder、Uri
查看>>
solr的suggest模块
查看>>
2PHP页面缓存
查看>>
编译原理 LL1文法First集算法实现
查看>>
菜鸟学Linux命令:bg fg jobs命令 任务管理
查看>>
python 多线程就这么简单(续)
查看>>
【Linux系统编程】 Linux系统调用概述
查看>>
SQL Server Reporting Services:无法检索应用程序文件。部署中的文件已损坏
查看>>
hive中partition如何使用
查看>>