6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, Math, StrUtils;
10 TMouseGesture = class(TObject)
14 FGestureItemList: TStringList;
15 FBeginGesture: Boolean;
21 FOnGestureStart: TNotifyEvent;
22 FOnGestureMove: TNotifyEvent;
23 FOnGestureEnd: TNotifyEvent;
24 function GetGestureCount: Integer;
25 function CheckAction(Message: Integer; x, y: Integer): Boolean;
26 procedure AddAction(sx, sy: Integer);
27 function AddGesture(Item: string): Integer;
28 procedure ClearGesture;
29 function Get(Index: integer): string;
30 procedure Put(Index: integer; Item: string);
33 destructor Destroy; override;
34 procedure SetHook(hWnd: THandle);
36 property Items[Index: Integer]: string read Get write Put; default;
37 property GestureCount: Integer read GetGestureCount;
38 property Margin: Integer read FMargin write FMargin;
39 function GetGestureStr: string;
40 property OnGestureStart: TNotifyEvent read FOnGestureStart write FOnGestureStart;
41 property OnGestureMove: TNotifyEvent read FOnGestureMove write FOnGestureMove;
42 property OnGestureEnd: TNotifyEvent read FOnGestureEnd write FOnGestureEnd;
45 function GestureProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
48 MouseGesture: TMouseGesture;
52 constructor TMouseGesture.Create;
57 FBeginGesture := False;
59 FGestureItemList := TStringList.Create;
62 destructor TMouseGesture.Destroy;
66 FGestureItemList.Free;
70 //
\83}
\83E
\83X
\83t
\83b
\83N
71 procedure TMouseGesture.SetHook(hWnd: THandle);
77 FHook := SetWindowsHookEx(WH_MOUSE, @GestureProc, 0{HInstance}, GetCurrentThreadId);
80 //
\83}
\83E
\83X
\83t
\83b
\83N
\89ð
\8f\9c
81 procedure TMouseGesture.UnHook;
85 UnhookWindowsHookEx(FHook);
89 //
\83t
\83b
\83N
\83v
\83\8d\83V
\83W
\83\83
90 function GestureProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
92 mhs: PMouseHookStruct;
94 if nCode = HC_ACTION then begin
95 mhs := PMouseHookStruct(lParam);
96 if MouseGesture.CheckAction(wParam, mhs^.pt.X, mhs^.pt.Y) then begin
101 Result := CallNextHookEx(MouseGesture.FHook, nCode, wParam, lParam);
104 function TMouseGesture.CheckAction(Message: Integer; x, y: Integer): Boolean;
113 if FBeginGesture then begin
114 //
\8d¡
\83}
\83E
\83X
\82ð
\83L
\83\83\83v
\83`
\83\83\81[
\82µ
\82Ä
\82¢
\82é
\82Ì
\82ð
\93¾
\82é
116 //
\83}
\83E
\83X
\83W
\83F
\83X
\83`
\83\83\81[
\82Ì
\91Î
\8fÛ
\82Æ
\88á
\82¤
\82Æ
\82«
\82Í
\81A
\8aJ
\95ú
\82·
\82é
117 if (hwnd <> 0) and (hwnd <> FHandle) then begin
121 dp := Point(x - FLastPoint.X, y - FLastPoint.Y);
122 sp := Point(Sign(dp.X), Sign(dp.Y));
123 if (dp.X * dp.X + dp.Y * dp.Y) > (FMargin * FMargin) then begin
124 dp := Point(Abs(dp.X), Abs(dp.Y));
125 if dp.X > dp.Y div 3 then
127 if dp.Y > dp.X div 3 then
129 AddAction(sp.X, sp.Y);
130 FLastTime := GetTickCount;
131 FLastPoint := Point(x, y);
136 WM_RBUTTONDOWN: begin
137 FBeginGesture := True;
139 FLastPoint := Point(x, y);
140 FStartPoint := Point(x, y);
144 FBeginGesture := False;
146 if FGestureItemList.Count <> 0 then begin
147 if Assigned(FOnGestureEnd) then
155 //
\93®
\8dì
\82Ì
\92Ç
\89Á
156 procedure TMouseGesture.AddAction(sx, sy: Integer);
161 if (sx > 0) and (sy = 0) then
163 else if (sx < 0) and (sy = 0) then
171 if FGestureItemList.Count > 0 then begin
172 if Items[FGestureItemList.Count - 1] = Direction then
175 //
\83W
\83F
\83X
\83`
\83\83\81[
\8aJ
\8en
176 if Assigned(FOnGestureStart) then
177 FOnGestureStart(Self);
179 AddGesture(Direction);
180 if Assigned(FOnGestureMove) then
181 FOnGestureMove(Self);
184 //
\8c»
\8dÝ
\82Ì
\83W
\83F
\83X
\83`
\83\83\81[
\82É
\90V
\82µ
\82¢
\95û
\8cü
\82ð
\92Ç
\89Á
185 function TMouseGesture.AddGesture(Item: string): Integer;
187 Result := FGestureItemList.Add(Item);
190 //
\8ew
\92è
\82³
\82ê
\82½index
\82Ì
\93®
\82«
\82ð
\95Ô
\82·
191 function TMouseGesture.Get(Index: Integer): string;
193 Result := FGestureItemList[Index];
196 //
\8ew
\92è
\82³
\82ê
\82½index
\82Ì
\93®
\82«
\82ð
\90Ý
\92è
\82·
\82é
197 procedure TMouseGesture.Put(Index: Integer; Item: string);
199 FGestureItemList[Index] := Item;
202 //
\83W
\83F
\83X
\83`
\83\83\81[
\95¶
\8e\9a\97ñ
\82ð
\95Ô
\82·
203 function TMouseGesture.GetGestureStr: string;
208 for i := 0 to FGestureItemList.Count - 1 do
209 Result := Result + Items[i];
212 //
\83W
\83F
\83X
\83`
\83\83\81[
\82Ì
\92·
\82³
\82ð
\95Ô
\82·
213 function TMouseGesture.GetGestureCount: Integer;
215 Result := FGestureItemList.Count;
218 //
\83W
\83F
\83X
\83`
\83\83\81[
\82ð
\83N
\83\8a\83A
\82·
\82é
219 procedure TMouseGesture.ClearGesture;
221 FGestureItemList.Clear;