学习 Message(3): 响应 WM_LBUTTONDOWN 消息
生活随笔
收集整理的這篇文章主要介紹了
学习 Message(3): 响应 WM_LBUTTONDOWN 消息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本例效果圖:
代碼文件:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Memo1: TMemo;procedure FormCreate(Sender: TObject);procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);protected{這句的輸入方法: Ctrl+空格; 輸入 moused 確認; 然后執行 Shift+Ctrl+C}procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); override;{這句的輸入方法: Ctrl+空格; 輸入 wmlbuttondo 確認; 然后執行 Shift+Ctrl+C}procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;end;varForm1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject); beginMemo1.Clear; end;{響應 WM_LBUTTONDOWN 消息的方法 1: OnMouseDown 事件} procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer); beginMemo1.Lines.Add('OnMouseDown'); end;{響應 WM_LBUTTONDOWN 消息的方法 2: 覆蓋父類的 MouseDown 方法} procedure TForm1.MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begininherited; {可以去掉或下移這句再試}Memo1.Lines.Add('MouseDown'); end;{響應 WM_LBUTTONDOWN 消息的方法 3: 直接使用消息方法} procedure TForm1.WMLButtonDown(var Message: TWMLButtonDown); beginMemo1.Lines.Add('WM_LBUTTONDOWN');inherited; {可以去掉或上移這句再試} end;end. 窗體文件:
object Form1: TForm1Left = 0Top = 0Caption = 'Form1'ClientHeight = 123ClientWidth = 233Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalseOnCreate = FormCreateOnMouseDown = FormMouseDownPixelsPerInch = 96TextHeight = 13object Memo1: TMemoLeft = 0Top = 0Width = 137Height = 123Align = alLeftLines.Strings = ('Memo1')ScrollBars = ssVerticalTabOrder = 0ExplicitHeight = 206end end
后面還有更多響應消息的辦法.
代碼文件:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Memo1: TMemo;procedure FormCreate(Sender: TObject);procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);protected{這句的輸入方法: Ctrl+空格; 輸入 moused 確認; 然后執行 Shift+Ctrl+C}procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); override;{這句的輸入方法: Ctrl+空格; 輸入 wmlbuttondo 確認; 然后執行 Shift+Ctrl+C}procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;end;varForm1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject); beginMemo1.Clear; end;{響應 WM_LBUTTONDOWN 消息的方法 1: OnMouseDown 事件} procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer); beginMemo1.Lines.Add('OnMouseDown'); end;{響應 WM_LBUTTONDOWN 消息的方法 2: 覆蓋父類的 MouseDown 方法} procedure TForm1.MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begininherited; {可以去掉或下移這句再試}Memo1.Lines.Add('MouseDown'); end;{響應 WM_LBUTTONDOWN 消息的方法 3: 直接使用消息方法} procedure TForm1.WMLButtonDown(var Message: TWMLButtonDown); beginMemo1.Lines.Add('WM_LBUTTONDOWN');inherited; {可以去掉或上移這句再試} end;end. 窗體文件:
object Form1: TForm1Left = 0Top = 0Caption = 'Form1'ClientHeight = 123ClientWidth = 233Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalseOnCreate = FormCreateOnMouseDown = FormMouseDownPixelsPerInch = 96TextHeight = 13object Memo1: TMemoLeft = 0Top = 0Width = 137Height = 123Align = alLeftLines.Strings = ('Memo1')ScrollBars = ssVerticalTabOrder = 0ExplicitHeight = 206end end
后面還有更多響應消息的辦法.
轉載于:https://www.cnblogs.com/del/archive/2008/10/24/1319062.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的学习 Message(3): 响应 WM_LBUTTONDOWN 消息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ngingx安装错误 ./configu
- 下一篇: IntelliJ IDEA添加jar包