-
Notifications
You must be signed in to change notification settings - Fork 24
/
Sensor.pas
184 lines (162 loc) · 5.15 KB
/
Sensor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
{
Copyright (C) 2006-2008 Matteo Salvi of SalvadorSoftware
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
}
unit Sensor;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, LCLType;
type
TfrmSensor = class(TForm)
procedure FormCreate(Sender: TObject);
procedure CreateParams(var Params: TCreateParams); override;
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ExecuteActionSensor(ArraySensor: Array of Integer);
private
{ Private declarations }
public
Side: Integer; //0 Top, 1 Left, 2 Right, 3 Bottom
{ Public declarations }
end;
function SetLayeredWindowAttributes(hwnd: LongInt;crKey: byte; bAlpha: byte;
dwFlags: LongInt): LongInt; stdcall;
external 'user32.dll' name 'SetLayeredWindowAttributes';
var
frmSensor : TfrmSensor;
const
crNewCur = 1;
{ Mouse Sensors}
procedure CreateFormSensors;
procedure CloseFormSensors;
implementation
uses Main, ulCommonUtils, ulAppConfig, AppConfig, udClassicMenu;
{$R *.dfm}
procedure CreateFormSensors;
var
I : Integer;
begin
//Create FormSensors and set its height and width
for I := 0 to 3 do
begin
frmSensor := nil;
case I of
0: //Top
begin
if (Config.SensorLeftClick[I] <> 0) or (Config.SensorRightClick[I] <> 0) then
begin
Application.CreateForm(TfrmSensor,frmSensor);
frmSensor.Height := 1;
frmSensor.Width := GetDeviceCaps(GetDC(frmMain.Handle), HORZRES);
//TODO QUESTO NON CAMBIA NULLA!
frmSensor.ShowInTaskBar:= stNever;
end
end;
1: //Left
begin
if (Config.SensorLeftClick[I] <> 0) or (Config.SensorRightClick[I] <> 0) then
begin
Application.CreateForm(TfrmSensor,frmSensor);
frmSensor.Height := GetDeviceCaps(GetDC(frmMain.Handle), VERTRES);
frmSensor.Width := 1;
end
end;
2: //Right
begin
if (Config.SensorLeftClick[I] <> 0) or (Config.SensorRightClick[I] <> 0) then
begin
Application.CreateForm(TfrmSensor,frmSensor);
frmSensor.Left := GetDeviceCaps(GetDC(frmMain.Handle), HORZRES) - 1;
frmSensor.Height := GetDeviceCaps(GetDC(frmMain.Handle), VERTRES);
frmSensor.Width := 1;
end
end;
3: //Bottom
begin
if (Config.SensorLeftClick[I] <> 0) or (Config.SensorRightClick[I] <> 0) then
begin
Application.CreateForm(TfrmSensor,frmSensor);
frmSensor.Top := GetDeviceCaps(GetDC(frmMain.Handle), VERTRES) - 1;
frmSensor.Height := 1;
frmSensor.Width := GetDeviceCaps(GetDC(frmMain.Handle), HORZRES);
end
end;
end;
//If assigned, show current frmSensor and set Side (to I)
//and FormSensors[I] (to current frmSensor)
if Assigned(frmSensor) then
begin
frmSensor.Show;
frmSensor.Side := I;
FormSensors[I] := frmSensor;
end;
end;
end;
procedure CloseFormSensors;
var
I : Integer;
begin
//If assigned, close and free FormSensors
for I := 0 to 3 do
if Assigned(FormSensors[I]) then
begin
FreeAndNil(FormSensors[i]);
end;
end;
procedure TfrmSensor.FormCreate(Sender: TObject);
begin
Screen.Cursors[crNewCur] := LoadCursorFromFile(PChar(SUITE_ICONS_PATH + 'asuite.cur'));
end;
procedure TfrmSensor.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
ExecuteActionSensor(Config.SensorLeftClick)
else
ExecuteActionSensor(Config.SensorRightClick);
end;
procedure TfrmSensor.ExecuteActionSensor(ArraySensor: Array of Integer);
Var Point: TPoint;
begin
with frmMain do
case ArraySensor[Side] of
1: ShowMainForm(self);
2: //Default Menu
begin
//TODO not yet converted from 1.X source
//if frmMenu.Visible then
// frmMenu.CloseMenu
//else
// frmMenu.OpenMenu;
end;
3: //Classic Menu
begin
ClassicMenu.ShowTrayiconMenu;
end;
end;
end;
procedure TfrmSensor.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
cursor := crNewCur;
end;
procedure TfrmSensor.CreateParams(var Params: TCreateParams);
begin
inherited;
//Transparent and sensor (form) topmost
Params.ExStyle := WS_EX_TRANSPARENT or WS_EX_TOOLWINDOW or WS_EX_TOPMOST;
Params.WndParent := GetDesktopWindow;
end;
end.