-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.ConfigForm.pas
542 lines (490 loc) · 17.9 KB
/
db.ConfigForm.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
unit db.ConfigForm;
interface
uses
Winapi.Windows, Winapi.Messages, Winapi.ShellAPI, System.SysUtils, System.Variants, System.Classes, System.IniFiles, System.Win.Registry,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtDlgs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.WinXCtrls, Vcl.Buttons, db.uCommon;
type
TfrmConfig = class(TForm)
lbl2: TLabel;
lbl3: TLabel;
lbl1: TLabel;
btnDatabaseConfig: TSpeedButton;
grpUI: TGroupBox;
lblTitle: TLabel;
edtTitle: TEdit;
chkShowTwoScreen: TCheckBox;
chkTopForm: TCheckBox;
chkCloseMini: TCheckBox;
srchbxBackImage: TSearchBox;
chkBackImage: TCheckBox;
chkAutorun: TCheckBox;
chkOnlyOneInstance: TCheckBox;
btnSave: TButton;
btnCancel: TButton;
rgShowStyle: TRadioGroup;
grpModuleSort: TGroupBox;
imgPModuleIcon: TImage;
imgSModuleIcon: TImage;
lblPModule: TLabel;
lblSModule: TLabel;
lstParentModule: TListBox;
lstSubModule: TListBox;
btnParentUp: TButton;
btnParentDown: TButton;
btnSubUp: TButton;
btnSubDown: TButton;
btnSubModuleIcon: TButton;
chkGray: TCheckBox;
btnPModuleIcon: TButton;
chkShowCloseButton: TCheckBox;
chkFullScreen: TCheckBox;
OpenPictureDialog1: TOpenPictureDialog;
btnAddEXE: TButton;
chkShowWebSpeed: TCheckBox;
procedure btnCancelClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnDatabaseConfigClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure srchbxBackImageInvokeSearch(Sender: TObject);
procedure chkBackImageClick(Sender: TObject);
procedure lstParentModuleClick(Sender: TObject);
procedure btnParentUpClick(Sender: TObject);
procedure btnParentDownClick(Sender: TObject);
procedure btnSubUpClick(Sender: TObject);
procedure btnSubDownClick(Sender: TObject);
procedure btnAddEXEClick(Sender: TObject);
procedure btnSubModuleIconClick(Sender: TObject);
procedure btnPModuleIconClick(Sender: TObject);
procedure lstSubModuleClick(Sender: TObject);
private
{ Private declarations }
FmemIni : TMemIniFile;
FlstModuleAll: THashedStringList;
FbResult : Boolean;
procedure ReadConfigFillUI;
procedure SaveConfig;
procedure FillSubModule(lstModule: TListBox; const strModuleName: string);
function CheckExeFile(const strPModuleName, strSModuleName: string; var strExeFileName: String): Boolean;
public
{ Public declarations }
end;
function ShowConfigForm(var lstModuleAll: THashedStringList): Boolean;
implementation
uses db.DBConfig, db.AddEXE;
{$R *.dfm}
function ShowConfigForm(var lstModuleAll: THashedStringList): Boolean;
begin
with TfrmConfig.Create(nil) do
begin
FbResult := False;
FlstModuleAll := lstModuleAll;
ReadConfigFillUI;
Position := poScreenCenter;
ShowModal;
Result := FbResult;
Free;
end;
end;
procedure TfrmConfig.btnDatabaseConfigClick(Sender: TObject);
begin
ShowDBConfigForm(FmemIni);
end;
{ 模块上移 }
procedure TfrmConfig.btnParentUpClick(Sender: TObject);
var
intSelectedIndex: Integer;
intPirorIndex : Integer;
strBackup : String;
begin
intSelectedIndex := lstParentModule.ItemIndex;
intPirorIndex := intSelectedIndex - 1;
if intPirorIndex >= 0 then
begin
strBackup := lstParentModule.Items.Strings[intPirorIndex];
lstParentModule.Items.Strings[intPirorIndex] := lstParentModule.Items.Strings[intSelectedIndex];
lstParentModule.Items.Strings[intSelectedIndex] := strBackup;
lstParentModule.Selected[intPirorIndex] := True;
end;
end;
{ 模块下移 }
procedure TfrmConfig.btnParentDownClick(Sender: TObject);
var
intSelectedIndex: Integer;
intNextIndex : Integer;
strBackup : String;
begin
intSelectedIndex := lstParentModule.ItemIndex;
intNextIndex := intSelectedIndex + 1;
if intNextIndex < lstParentModule.Count then
begin
strBackup := lstParentModule.Items.Strings[intNextIndex];
lstParentModule.Items.Strings[intNextIndex] := lstParentModule.Items.Strings[intSelectedIndex];
lstParentModule.Items.Strings[intSelectedIndex] := strBackup;
lstParentModule.Selected[intNextIndex] := True;
end;
end;
{ 添加 EXE }
procedure TfrmConfig.btnAddEXEClick(Sender: TObject);
var
strPModuleName, strSModuleName, strFormClassName, strFormTitleName, strExeFileName: string;
begin
if lstParentModule.ItemIndex = -1 then
strPModuleName := ''
else
strPModuleName := lstParentModule.Items.Strings[lstParentModule.ItemIndex];
if ShowAddEXEForm(strPModuleName, strSModuleName, strFormClassName, strFormTitleName, strExeFileName) then
begin
FmemIni.WriteString('EXE', strExeFileName, Format('%s;%s;%s;%s', [strPModuleName, strSModuleName, strFormClassName, strFormTitleName]));
lstSubModule.ItemIndex := lstSubModule.Items.Add(strSModuleName);
FlstModuleAll.Add(Format('%s=%s;%s;%s;%s;', [strExeFileName, strPModuleName, strSModuleName, strFormClassName, strFormTitleName]));
lstSubModule.OnClick(nil);
end;
end;
procedure TfrmConfig.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure EnableAutoRun(const bAutoRun: Boolean = False);
begin
if not bAutoRun then
begin
with TRegistry.Create do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
DeleteValue('PBox');
Free;
end;
end
else
begin
with TRegistry.Create do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
WriteString('PBox', ParamStr(0));
Free;
end;
end;
end;
procedure TfrmConfig.SaveConfig;
begin
FmemIni.WriteString(c_strIniUISection, 'Title', edtTitle.Text);
FmemIni.WriteBool(c_strIniUISection, 'MulScreen', chkShowTwoScreen.Checked);
FmemIni.WriteBool(c_strIniUISection, 'OnTop', chkTopForm.Checked);
FmemIni.WriteBool(c_strIniUISection, 'MAXSIZE', chkFullScreen.Checked);
FmemIni.WriteBool(c_strIniUISection, 'CloseMini', chkCloseMini.Checked);
FmemIni.WriteBool(c_strIniUISection, 'AutoRun', chkAutorun.Checked);
FmemIni.WriteBool(c_strIniUISection, 'OnlyOneInstance', chkOnlyOneInstance.Checked);
FmemIni.WriteBool(c_strIniUISection, 'ShowWebSpeed', chkShowWebSpeed.Checked);
FmemIni.WriteBool(c_strIniUISection, 'ShowBackImage', chkBackImage.Checked);
FmemIni.WriteInteger(c_strIniFormStyleSection, 'index', rgShowStyle.ItemIndex);
FmemIni.WriteBool(c_strIniFormStyleSection, 'ShowCloseButton', chkShowCloseButton.Checked);
if chkBackImage.Checked then
FmemIni.WriteString(c_strIniUISection, 'filebackimage', srchbxBackImage.Text)
else
FmemIni.WriteString(c_strIniUISection, 'filebackimage', '');
EnableAutoRun(chkAutorun.Checked);
lstParentModule.Items.Delimiter := ';';
FmemIni.WriteString(c_strIniModuleSection, 'Order', lstParentModule.Items.DelimitedText);
end;
procedure TfrmConfig.ReadConfigFillUI;
var
I : Integer;
strPModuleName: String;
begin
edtTitle.Text := FmemIni.ReadString(c_strIniUISection, 'Title', c_strTitle);
chkShowTwoScreen.Checked := FmemIni.ReadBool(c_strIniUISection, 'MulScreen', False) and (Screen.MonitorCount > 1);
chkTopForm.Checked := FmemIni.ReadBool(c_strIniUISection, 'OnTop', False);
chkFullScreen.Checked := FmemIni.ReadBool(c_strIniUISection, 'MAXSIZE', False);
chkCloseMini.Checked := FmemIni.ReadBool(c_strIniUISection, 'CloseMini', False);
chkAutorun.Checked := FmemIni.ReadBool(c_strIniUISection, 'AutoRun', False);
chkOnlyOneInstance.Checked := FmemIni.ReadBool(c_strIniUISection, 'OnlyOneInstance', True);
chkShowWebSpeed.Checked := FmemIni.ReadBool(c_strIniUISection, 'ShowWebSpeed', False);
chkBackImage.Checked := FmemIni.ReadBool(c_strIniUISection, 'ShowBackImage', False);
if chkBackImage.Checked then
srchbxBackImage.Text := FmemIni.ReadString(c_strIniUISection, 'filebackimage', '');
rgShowStyle.ItemIndex := FmemIni.ReadInteger(c_strIniFormStyleSection, 'index', 0);
chkShowCloseButton.Checked := FmemIni.ReadBool(c_strIniFormStyleSection, 'ShowCloseButton', True);
{ 模块列表 }
for I := 0 to FlstModuleAll.Count - 1 do
begin
strPModuleName := FlstModuleAll.ValueFromIndex[I].Split([';'])[0];
if lstParentModule.Items.IndexOf(strPModuleName) = -1 then
lstParentModule.Items.Add(strPModuleName);
end;
end;
procedure TfrmConfig.srchbxBackImageInvokeSearch(Sender: TObject);
begin
with TOpenPictureDialog.Create(nil) do
begin
Filter := '背景图片(*.JPG;*.BMP;*PNG)|*.JPG;*.BMP;*PNG';
if Execute() then
begin
srchbxBackImage.Text := FileName;
FmemIni.WriteBool(c_strIniUISection, 'showbackimage', chkBackImage.Checked);
FmemIni.WriteString(c_strIniUISection, 'filebackimage', FileName);
end;
Free;
end;
end;
procedure TfrmConfig.btnSaveClick(Sender: TObject);
begin
FbResult := True;
SaveConfig;
FmemIni.UpdateFile;
{ 排序模块 }
SortModuleList(FlstModuleAll);
Close;
end;
{ 子模块上移 }
procedure TfrmConfig.btnSubUpClick(Sender: TObject);
var
intSelectedIndex: Integer;
intPirorIndex : Integer;
strBackup : String;
begin
intSelectedIndex := lstSubModule.ItemIndex;
intPirorIndex := intSelectedIndex - 1;
if intPirorIndex >= 0 then
begin
strBackup := lstSubModule.Items.Strings[intPirorIndex];
lstSubModule.Items.Strings[intPirorIndex] := lstSubModule.Items.Strings[intSelectedIndex];
lstSubModule.Items.Strings[intSelectedIndex] := strBackup;
lstSubModule.Selected[intPirorIndex] := True;
lstSubModule.Items.Delimiter := ';';
FmemIni.WriteString(c_strIniModuleSection, lstParentModule.Items.Strings[lstParentModule.ItemIndex], lstSubModule.Items.DelimitedText);
end;
end;
{ 子模块下移 }
procedure TfrmConfig.btnSubDownClick(Sender: TObject);
var
intSelectedIndex: Integer;
intNextIndex : Integer;
strBackup : String;
begin
intSelectedIndex := lstSubModule.ItemIndex;
intNextIndex := intSelectedIndex + 1;
if intNextIndex < lstSubModule.Count then
begin
strBackup := lstSubModule.Items.Strings[intNextIndex];
lstSubModule.Items.Strings[intNextIndex] := lstSubModule.Items.Strings[intSelectedIndex];
lstSubModule.Items.Strings[intSelectedIndex] := strBackup;
lstSubModule.Selected[intNextIndex] := True;
lstSubModule.Items.Delimiter := ';';
FmemIni.WriteString(c_strIniModuleSection, lstParentModule.Items.Strings[lstParentModule.ItemIndex], lstSubModule.Items.DelimitedText);
end;
end;
procedure TfrmConfig.chkBackImageClick(Sender: TObject);
begin
if chkBackImage.Checked then
begin
srchbxBackImage.Visible := True;
srchbxBackImage.Text := FmemIni.ReadString(c_strIniUISection, 'filebackimage', '');
end
else
begin
srchbxBackImage.Visible := False;
srchbxBackImage.Text := '';
end;
end;
procedure TfrmConfig.FormCreate(Sender: TObject);
begin
FmemIni := TMemIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
end;
procedure TfrmConfig.FormDestroy(Sender: TObject);
begin
FmemIni.Free;
end;
{ 设置父模块显示图标 }
procedure TfrmConfig.btnPModuleIconClick(Sender: TObject);
var
strIconFilePath: String;
begin
if lstParentModule.ItemIndex < 0 then
begin
MessageBox(Application.MainForm.Handle, '必须从父模块列表中选择一个模块', '系统提示:', MB_OK OR MB_ICONINFORMATION);
lstParentModule.SetFocus;
Exit;
end;
with TOpenDialog.Create(nil) do
begin
Filter := '图标文件(*.ico)|*.ico';
if Execute(Application.MainForm.Handle) then
begin
with TPicture.Create do
begin
LoadFromFile(FileName);
strIconFilePath := ExtractFilePath(ParamStr(0)) + 'plugins\Icon\' + ExtractFileName(FileName);
if not DirectoryExists(ExtractFilePath(strIconFilePath)) then
ForceDirectories(ExtractFilePath(strIconFilePath));
CopyFile(PChar(FileName), PChar(strIconFilePath), False);
FmemIni.WriteString(c_strIniModuleSection, lstParentModule.Items.Strings[lstParentModule.ItemIndex] + '_ICON', ExtractFileName(FileName));
imgPModuleIcon.Picture.LoadFromFile(strIconFilePath);
Free;
end;
end;
Free;
end;
end;
{ 设置子模块显示图标 }
procedure TfrmConfig.btnSubModuleIconClick(Sender: TObject);
var
strIconFilePath : String;
strPModuleName, strSModuleName: String;
begin
if lstParentModule.ItemIndex < 0 then
begin
MessageBox(Application.MainForm.Handle, '必须从父模块列表中选择一个模块', '系统提示:', MB_OK OR MB_ICONINFORMATION);
lstParentModule.SetFocus;
Exit;
end;
if lstSubModule.ItemIndex < 0 then
begin
MessageBox(Application.MainForm.Handle, '必须从子模块列表中选择一个模块', '系统提示:', MB_OK OR MB_ICONINFORMATION);
lstSubModule.SetFocus;
Exit;
end;
strPModuleName := lstParentModule.Items.Strings[lstParentModule.ItemIndex];
strSModuleName := lstSubModule.Items.Strings[lstSubModule.ItemIndex];
with TOpenDialog.Create(nil) do
begin
Filter := '图标文件(*.ico)|*.ico';
if Execute(Application.MainForm.Handle) then
begin
with TPicture.Create do
begin
LoadFromFile(FileName);
strIconFilePath := ExtractFilePath(ParamStr(0)) + 'plugins\Icon\' + ExtractFileName(FileName);
if not DirectoryExists(ExtractFilePath(strIconFilePath)) then
ForceDirectories(ExtractFilePath(strIconFilePath));
CopyFile(PChar(FileName), PChar(strIconFilePath), False);
FmemIni.WriteString(c_strIniModuleSection, String(strPModuleName) + '_' + string(strSModuleName) + '_ICON', ExtractFileName(FileName));
imgSModuleIcon.Picture.LoadFromFile(strIconFilePath);
Free;
end;
end;
Free;
end;
end;
procedure TfrmConfig.FillSubModule(lstModule: TListBox; const strModuleName: string);
var
strPModuleName: string;
strSModuleName: string;
I : Integer;
begin
{ 模块列表 }
for I := 0 to FlstModuleAll.Count - 1 do
begin
strPModuleName := FlstModuleAll.ValueFromIndex[I].Split([';'])[0];
strSModuleName := FlstModuleAll.ValueFromIndex[I].Split([';'])[1];
if CompareText(strModuleName, strPModuleName) = 0 then
begin
lstModule.Items.Add(strSModuleName);
end;
end;
end;
procedure TfrmConfig.lstParentModuleClick(Sender: TObject);
var
strPModuleName : string;
strPModuleIconFileName: String;
begin
if lstParentModule.ItemIndex < 0 then
Exit;
if lstParentModule.SelCount = 0 then
Exit;
{ 父模块图标 }
imgPModuleIcon.Picture.Assign(nil);
imgSModuleIcon.Picture.Assign(nil);
strPModuleIconFileName := FmemIni.ReadString(c_strIniModuleSection, lstParentModule.Items.Strings[lstParentModule.ItemIndex] + '_ICON', '');
strPModuleIconFileName := ExtractFilePath(ParamStr(0)) + 'plugins\Icon\' + strPModuleIconFileName;
if FileExists(strPModuleIconFileName) then
begin
with TPicture.Create do
begin
LoadFromFile(strPModuleIconFileName);
imgPModuleIcon.Picture.LoadFromFile(strPModuleIconFileName);
Free;
end;
end;
{ 子模块列表 }
lstSubModule.Clear;
strPModuleName := lstParentModule.Items.Strings[lstParentModule.ItemIndex];
FillSubModule(lstSubModule, strPModuleName);
end;
function TfrmConfig.CheckExeFile(const strPModuleName, strSModuleName: string; var strExeFileName: String): Boolean;
var
I : Integer;
strParentModuleName: String;
strSubModuleName : String;
begin
Result := False;
for I := 0 to FlstModuleAll.Count - 1 do
begin
strParentModuleName := FlstModuleAll.ValueFromIndex[I].Split([';'])[0];
strSubModuleName := FlstModuleAll.ValueFromIndex[I].Split([';'])[1];
if (CompareText(strParentModuleName, strPModuleName) = 0) and (CompareText(strSubModuleName, strSModuleName) = 0) then
begin
strExeFileName := FlstModuleAll.Names[I];
Result := (CompareText('.exe', ExtractFileExt(strExeFileName)) = 0) or (CompareText('.msc', ExtractFileExt(strExeFileName)) = 0);
Break;
end;
end;
end;
procedure TfrmConfig.lstSubModuleClick(Sender: TObject);
var
strPModuleName, strSModuleName: String;
strIconFileName : String;
strExeFileName : String;
IcoExe : TIcon;
begin
if lstParentModule.ItemIndex < 0 then
Exit;
if lstSubModule.ItemIndex < 0 then
Exit;
imgSModuleIcon.Picture.Assign(nil);
strPModuleName := lstParentModule.Items.Strings[lstParentModule.ItemIndex];
strSModuleName := lstSubModule.Items.Strings[lstSubModule.ItemIndex];
if CheckExeFile(strPModuleName, strSModuleName, strExeFileName) then
begin
btnSubModuleIcon.Enabled := False;
imgSModuleIcon.Enabled := False;
if CompareText(ExtractFileExt(strExeFileName), '.exe') = 0 then
begin
if ExtractIcon(HInstance, PChar(strExeFileName), $FFFFFFFF) > 0 then
begin
IcoExe := TIcon.Create;
try
IcoExe.Handle := ExtractIcon(HInstance, PChar(strExeFileName), 0);
imgSModuleIcon.Picture.Assign(IcoExe);
finally
IcoExe.Free;
end;
end;
end;
if CompareText(ExtractFileExt(strExeFileName), '.msc') = 0 then
begin
IcoExe := TIcon.Create;
try
LoadIconFromMSCFile(strExeFileName, IcoExe);
imgSModuleIcon.Picture.Assign(IcoExe);
finally
IcoExe.Free;
end;
end;
end
else
begin
btnSubModuleIcon.Enabled := True;
imgSModuleIcon.Enabled := True;
chkGray.Checked := FmemIni.ReadBool(c_strIniModuleSection, String(strPModuleName) + '_' + string(strSModuleName) + '_HIDE', False);
strIconFileName := FmemIni.ReadString(c_strIniModuleSection, strPModuleName + '_' + strSModuleName + '_ICON', '');
strIconFileName := ExtractFilePath(ParamStr(0)) + 'plugins\Icon\' + strIconFileName;
if FileExists(strIconFileName) then
begin
imgSModuleIcon.Picture.LoadFromFile(strIconFileName);
end;
end;
end;
end.