-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSettings_src.pas
343 lines (314 loc) · 9.56 KB
/
Settings_src.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
unit Settings_src;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg, StdCtrls, XPMan;
type
TForm2 = class(TForm)
Image1: TImage;
Image2: TImage;
Shape1: TShape;
Shape2: TShape;
Label1: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
XPManifest1: TXPManifest;
chkSmartSwitch: TCheckBox;
chkBackground: TCheckBox;
chkAeroPeek: TCheckBox;
CheckBox1: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure chkAeroPeekMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
procedure CreateParams(var Params: TCreateParams);override;
procedure CloseApp(Sender: TObject);
procedure UpdatePosition;
public
{ Public declarations }
end;
var
Form2: TForm2;
procedure SwitchToThisWindow(h1: hWnd; x: bool); stdcall;
external user32 Name 'SwitchToThisWindow';
implementation
uses Win7se_src, CommCtrl, Registry;
{$R *.dfm}
procedure tForm2.UpdatePosition;
var
Shell_TrayWnd: HWND; // la barra completa
// TrayNotifyWnd: HWND; // la bandeja de sistema
Shell_TrayWndRect: TRect;
//TrayNotifyWndRect: TRect;
// let's locate the taskbar position and according to that repos this form
begin
Shell_TrayWnd:=FindWindow('Shell_TrayWnd',nil);
if Shell_TrayWnd>0 then
begin
// TrayNotifyWnd:=FindWindowEx(Shell_TrayWnd,HWND(0),'TrayNotifyWnd',nil);
// if TrayNotifyWnd>0 then
begin
GetWindowRect(Shell_TrayWnd,Shell_TrayWndRect);
// GetWindowRect(TrayNotifyWnd,TrayNotifyWndRect);
// ShowMessage('Left: '+inttostr(Shell_TrayWndRect.Left)+ ' Top: '+inttostr(Shell_TrayWndRect.Top)+ ' Right: '+inttostr(Shell_TrayWndRect.Right)+ ' Bottom: '+inttostr(Shell_TrayWndRect.Bottom) +#13+'Screen.Width: '+inttostr(Screen.Width)+' Screen.Height: '+inttostr(Screen.Height));
//bottom
if (Shell_TrayWndRect.Left=0)
and(Shell_TrayWndRect.Right=Screen.Width)
and(Shell_TrayWndRect.Top>0)
then
begin
//ShowMessage('está abajo')
//posicionamos a la derecha en el systray
Left:=Screen.Width-Width-10;
if Left<1 then Left:=10;
Top:=Screen.Height-Height-Shell_TrayWndRect.Bottom+Shell_TrayWndRect.Top-10;
if Top<1 then Top:=10;
end
//arriba
else if (Shell_TrayWndRect.Left=0)
and(Shell_TrayWndRect.Right=Screen.Width)
and(Shell_TrayWndRect.Top<1)
then
begin
//ShowMessage('Está arriba');
Left:=Screen.Width-Width-10;
if Left<1 then Left:=10;
Top:=Shell_TrayWndRect.Bottom+10;
if Top<1 then Top:=10;
end
//izquierda
else if (Shell_TrayWndRect.Left<1)
and (Shell_TrayWndRect.Top=0)
and(Shell_TrayWndRect.Bottom=Screen.Height)
then
begin
//ShowMessage('Está a la izquierda')
Left:=Shell_TrayWndRect.Right+10;
if Left<1 then Left:=10;
Top:=Screen.Height-Height-10;
if Top<1 then Top:=10;
end
//derecha
else if (Shell_TrayWndRect.Left>0)
and(Shell_TrayWndRect.Top=0)
and(Shell_TrayWndRect.Bottom=Screen.Height)
then
begin
//ShowMessage('Está a la derecha');
Left:=Shell_TrayWndRect.Left-Width-10;
if Left<1 then Left:=10;
Top:=Screen.Height-Height-10;
if Top<1 then Top:=10;
end;
end;
end;
end;
procedure tform2.CloseApp(Sender: TObject);
begin
close;
end;
function AeroPeekState:Boolean;
var
reg: TRegistry;
begin
Result:=False; //default disabled
reg:=TRegistry.Create;
try
reg.RootKey:=HKEY_CURRENT_USER;
if reg.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows\DWM') then
begin
if reg.ReadInteger('EnableAeroPeek') = 1 then Result := True
else Result:=false;
reg.CloseKey;
end;
finally
reg.free;
end;
end;
procedure EnableAeroPeek;
var
reg: TRegistry;
begin
reg:=TRegistry.Create;
try
reg.RootKey:=HKEY_CURRENT_USER;
if reg.OpenKey('SOFTWARE\Microsoft\Windows\DWM',True) then
begin
reg.WriteInteger('EnableAeroPeek',1);
reg.CloseKey;
end;
finally
reg.Free;
end;
end;
procedure DisableAeroPeek;
var
reg: TRegistry;
begin
reg:=TRegistry.Create;
try
reg.RootKey:=HKEY_CURRENT_USER;
if reg.OpenKey('SOFTWARE\Microsoft\Windows\DWM',True) then
begin
reg.WriteInteger('EnableAeroPeek',0);
reg.CloseKey;
end;
finally
reg.Free;
end;
end;
procedure ShowBallonTip(Control: TWinControl; Icon: integer; Title: Pchar; text:pwidechar;
backcl, textcl: tcolor);
const
TOOLTIPS_CLASS = 'tooltips_class32';
TTS_ALWAYSTIP = $01;
TTS_NOPREFIX = $02;
TTS_BALLOON = $40;
TTF_SUBCLASS = $0010;
TTF_TRANSPARENT = $0100;
TTF_CENTERTIP = $0002;
TTM_ADDTOOL = $0400 + 50;
TTM_SETTITLE = (WM_USER + 32);
ICC_WIN95_CLASSES = $000000FF;
type
TOOLINFO = packed record
cbSize: Integer;
uFlags: Integer;
hwnd: THandle;
uId: Integer;
rect: TRect;
hinst: THandle;
lpszText: PWideChar;
lParam: Integer;
end;
var
hWndTip: THandle;
ti: TOOLINFO;
hWnd: THandle;
begin
hWnd:=Control.Handle;
hWndTip:=CreateWindow(TOOLTIPS_CLASS,nil,
WS_POPUP or TTS_NOPREFIX or TTS_BALLOON or TTS_ALWAYSTIP,
0,0,0,0, hWnd,0,HInstance,nil);
if hWndTip <> 0 then
begin
SetWindowPos(hWndTip,HWND_TOPMOST,0,0,0,0,
SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
ti.cbSize:=SizeOf(ti);
ti.uFlags:=TTF_CENTERTIP or TTF_TRANSPARENT or TTF_SUBCLASS;
ti.hwnd:=hWnd;
ti.lpszText:=Text;
Windows.GetClientRect(hwnd,ti.rect);
SendMessage(hWndTip, TTM_SETTIPBKCOLOR, backcl,0);
SendMessage(hWndTip, TTM_SETTIPTEXTCOLOR, textcl,0);
SendMessage(hWndTip,TTM_ADDTOOL, 1, Integer(@ti));
SendMessage(hWndTip,TTM_SETTITLE,Icon mod 4, Integer(Title));
end;
end;
procedure TForm2.WMNCHitTest(var Message: TWMNCHitTest);
begin
inherited;
if (message.Result = htbottom)
or (message.Result = htbottomleft)
or (message.Result = htbottomright)
or (message.Result = htleft)
or (message.Result = htright)
or (message.Result = httop)
or (message.Result = httopleft)
or (message.Result = httopright)
then message.Result := HTBORDER;
// if Message.Result = htclient then Message.Result:=HTCAPTION;
end;
procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style:=Params.Style or WS_THICKFRAME;
end;
procedure TForm2.FormCreate(Sender: TObject);
var
cursorpos: TPoint;
i: integer;
begin
Application.OnDeactivate:=CloseApp;
try
cursorpos:= mouse.CursorPos;
except
end;
Form2.Left:=cursorpos.X;
Form2.Top:=cursorpos.Y;
if form2.Top + form2.Height > Screen.Height then
Form2.Top:=Screen.Height-form2.Height-20;
if Form2.Left + form2.Width > Screen.Width then
Form2.Left:=Screen.Width-form2.Width-20;
//Embellecemos la ventana Win7 like
BorderStyle:=bsNone;
Color:=clWhite;
// La forma de abajo celeste o parecido
Shape1.Brush.Color:=$FbF5F1;
Shape1.Pen.Color:=$FbF5F1;
Shape1.Height:=41;
Shape1.Align:=alBottom;
Shape2.Pen.Color:=$eaD9cc;
Shape2.Height:=1;
Shape2.Align:=alBottom;
//color chéver para el enlace about
with Label1 do begin
Font.Style:=[fsBold];
Caption:='About Win7sé';
AutoSize:=False;
Width:=Form2.Width;
Left:=0;
Alignment:=taCenter;
Cursor:=crHandPoint;
font.Color:=$FF901E;
end;
Image1.Top:=16;
Image1.Left:=Image2.Left;
Image2.Top:=16;
Image2.Visible:=False;
//opciones del combo box
ComboBox1.Items.Clear;ComboBox1.Text:='';ComboBox1.Style:=csDropDownList;
ComboBox2.Items.Clear;ComboBox2.Text:='';ComboBox2.Style:=csDropDownList;
ComboBox3.Items.Clear;ComboBox3.Text:='';ComboBox3.Style:=csDropDownList;
ComboBox4.Items.Clear;ComboBox4.Text:='';ComboBox4.Style:=csDropDownList;
for i:=0 to Length(Win7se_src.Actions)-1 do
begin
ComboBox1.Items.Add(Win7se_src.Actions[i]);
ComboBox2.Items.Add(Win7se_src.Actions[i]);
ComboBox3.Items.Add(Win7se_src.Actions[i]);
ComboBox4.Items.Add(Win7se_src.Actions[i]);
end;
//hiding from taskbar
ShowWindow(Application.Handle, SW_HIDE) ;
SetWindowLong(Application.Handle, GWL_EXSTYLE, getWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW) ;
ShowWindow(Application.Handle, SW_SHOW) ;
FormStyle:=fsStayOnTop;
//it hides the app from alt tab
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
chkAeroPeek.Checked:=AeroPeekState;
//va después de la modificacion de estilo de ventana sino no funciona
ShowBallonTip(chkSmartSwitch,1,'Smart switch','Cycle to desired app with mousewheel and return to corner to switch, no click required!',clBlue,clRed);
end;
procedure TForm2.FormShow(Sender: TObject);
begin
SwitchToThisWindow(Form2.Handle,True);
Win7se_src.ToggleForm2:=true;
UpdatePosition;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Win7se_src.ToggleForm2:=false;
end;
procedure TForm2.chkAeroPeekMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if chkAeroPeek.Checked then EnableAeroPeek
else DisableAeroPeek
end;
end.