This repository has been archived by the owner on Oct 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
SelListForm.pas
726 lines (680 loc) · 22.1 KB
/
SelListForm.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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
unit SelListForm;
(*
CCA is a tool to evaluate the color visibility and contrast of foreground/background color combinations.
Copyright (C) 2014 The Paciello Group
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, System.Types,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, JPEG, iniFiles, ShlObj , AccCTRLs, System.Math,
ComObj, Funcs;
type
TBMPs = record
Title: String;
hWindow: THandle;
N_BMP, P_BMP, D_BMP, T_BMP, G_BMP, I_BMP, C_BMP: TBitmap;
end;
PWnd = ^TWnd;
TWnd = record
Title: String;
hWindow: THandle;
end;
TfrmSelList = class(TForm)
ScrollBox1: TScrollBox;
Image1: TImage;
SaveDialog1: TSaveDialog;
ScrollBox2: TScrollBox;
gbSimulation: TAccGroupBox;
btnSave: TAccButton;
btnPreview: TAccButton;
ComboBox2: TAccComboBox;
gbWndList: TAccGroupBox;
ComboBox1: TAccComboBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnPreviewClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure btnSaveClick(Sender: TObject);
private
{ Private 錾 }
function ScreenShot:Boolean;
procedure ShowProg(Mode: integer);
procedure WMDPIChanged(var Message: TMessage); message WM_DPICHANGED;
public
{ Public 錾 }
SPath:string;
FBMPs: TBMPs;
ScaleY, ScaleX, Dx, Dy: double;
DefFont: integer;
procedure ResizeCtrls;
end;
var
frmSelList: TfrmSelList;
WList: TList;
implementation
uses Main, ProgressForm;
{$R *.dfm}
function EnumWnd(hWindow:HWND; lPar:LPARAM):Boolean; stdcall;
var
Buf, s: array [0..255] of Char;
FWnd: PWnd;
i: Integer;
TA: Boolean;
begin
if IsWindowVisible(hWindow) then
begin
TA := False;
i := GetWindowText(hWindow, Buf, 255);
New(FWnd);
if i <> 0 then
begin
StrLCopy(s, buf, i);
FWnd.Title := s;
end
else
FWnd.Title := '';
FWnd.hWindow := hWindow;
i := GetClassName(hWindow, Buf, 255);
if i <> 0 then
begin
StrLCopy(s, buf, i);
if FWnd.Title = '' then
FWnd.Title := s;// + '(ClassName)';
if (LowerCase(s) <> 'progman') and (LowerCase(s) <> 'tapplication') then
begin
if (hWindow = MainForm.Handle) or (Application.Handle = hWindow) then
begin
TA := True;
end;
end
else
TA := True;
end;
if (not TA) then WList.Add(FWnd)
else Dispose(FWnd);
end;
Result := True;
end;
function GetMyDocPath: string;
var
IIDList: PItemIDList;
buffer: array [0..MAX_PATH - 1] of char;
begin
IIDList := nil;
OleCheck(SHGetSpecialFolderLocation(Application.Handle,
CSIDL_PERSONAL, IIDList));
if not SHGetPathFromIDList(IIDList, buffer) then
begin
raise Exception.Create('The folder path cannot be acquired, because the folder is a virtual folder.');
end;
Result := StrPas(Buffer);
end;
procedure TfrmSelList.FormCreate(Sender: TObject);
var
i: Integer;
DWnd: HWND;
FWnd: PWnd;
ini: TMemIniFile;
begin
WList := TList.Create;
DWnd := GetDesktopWindow;
SPath := IncludeTrailingPathDelimiter(GetMyDocPath) + 'CCA.ini';
if DWnd <> 0 then
begin
New(FWnd);
FWnd.Title := 'Desktop';
FWnd.hWindow := DWnd;
WList.Add(FWnd);
end;
EnumWindows(@EnumWnd, LPARAM(0));
if WList.Count > 0 then
begin
for i := 0 to WList.Count - 1 do
begin
ComboBox1.Items.Add(PWnd(WList.Items[i])^.Title + '(' + IntToHEX(PWnd(WList.Items[i])^.hWindow, 2) + ')');
end;
ComboBox1.ItemIndex := 0;
end
else
begin
btnSave.Enabled := False;
btnPreview.Enabled := False;
end;
ini := TMemIniFile.Create(SPath, TEncoding.Unicode);
try
//edtC_Quality.Value := ini.ReadInteger('JPEG', 'Compression', 75);
//chkSmooth.Checked := ini.ReadBool('JPEG', 'Smooth', False);
Left := ini.ReadInteger('Window', 'SelList_Left', (Screen.WorkAreaWidth div 2) - (Width div 2));
Top := ini.ReadInteger('Window', 'SelList_Top', (Screen.WorkAreaHeight div 2) - (Height div 2));
Width := ini.ReadInteger('Window', 'SelList_Width', 800);
Height := ini.ReadInteger('Window', 'SelList_Height', 600);
finally
ini.Free;
end;
if Width < Constraints.MinWidth then
Width := Constraints.MinWidth;
if Height < Constraints.MinHeight then
Height := Constraints.MinHeight;
Caption := MainForm.GetTranslation('wnd_list', 'Window list');
gbWndList.Caption := MainForm.GetTranslation('sel_wnd', 'Select window');
gbSimulation.Caption := MainForm.GetTranslation('simulation', 'Simulation');
//gbJPEG.Caption := MainForm.GetTranslation('jpeg_options', 'JPEG options');
btnSave.Caption := MainForm.GetTranslation('save', '&Save');
btnPreview.Caption := MainForm.GetTranslation('preview', '&Preview');
//lblC_Quality.Caption := MainForm.GetTranslation('compression_quality', 'Compression Quality:');
//chkSmooth.Caption := MainForm.GetTranslation('smoothing', 'S&moothing');
//btnClose.Caption := MainForm.GetTranslation('close', '&Close');
ComboBox2.Items.Add(MainForm.GetTranslation('protanopia', 'Protanopia'));
ComboBox2.Items.Add(MainForm.GetTranslation('deuteranopia', 'Deuteranopia'));
ComboBox2.Items.Add(MainForm.GetTranslation('tritanopia', 'Tritanopia'));
ComboBox2.Items.Add(MainForm.GetTranslation('grayscale', 'Grayscale'));
ComboBox2.Items.Add(MainForm.GetTranslation('invert', 'Invert'));
ComboBox2.Items.Add(MainForm.GetTranslation('cataracts', 'Cataracts'));
ComboBox2.Items.Add(MainForm.GetTranslation('normal', 'Normal'));
ComboBox2.ItemIndex := 0;
//ResizeCtrls;
end;
procedure TfrmSelList.FormClose(Sender: TObject; var Action: TCloseAction);
var
i: integer;
ini: TMemIniFile;
begin
ini := TMemIniFile.Create(SPath, TEncoding.Unicode);
try
//ini.WriteInteger('JPEG', 'Compression', edtC_Quality.AsInteger);
//ini.WriteBool('JPEG', 'Smooth', chkSmooth.Checked);
ini.WriteInteger('Window', 'SelList_Left', Left);
ini.WriteInteger('Window', 'SelList_Top', Top);
ini.WriteInteger('Window', 'SelList_Width', Width);
ini.WriteInteger('Window', 'SelList_Height', Height);
ini.UpdateFile;
finally
ini.Free;
end;
for i := 0 to WList.Count - 1 do
begin
DisPose(PWnd(WList.Items[i]));
end;
if Assigned(FBMPs.P_BMP) then
begin
FBMPs.P_BMP.FreeImage;
FreeAndNil(FBMPs.P_BMP);
end;
if Assigned(FBMPs.D_BMP) then
begin
FBMPs.D_BMP.FreeImage;
FreeAndNil(FBMPs.D_BMP);
end;
if Assigned(FBMPs.T_BMP) then
begin
FBMPs.T_BMP.FreeImage;
FreeAndNil(FBMPs.T_BMP);
end;
if Assigned(FBMPs.I_BMP) then
begin
FBMPs.I_BMP.FreeImage;
FreeAndNil(FBMPs.I_BMP);
end;
if Assigned(FBMPs.G_BMP) then
begin
FBMPs.G_BMP.FreeImage;
FreeAndNil(FBMPs.G_BMP);
end;
if Assigned(FBMPs.N_BMP) then
begin
FBMPs.N_BMP.FreeImage;
FreeAndNil(FBMPs.N_BMP);
end;
if Assigned(FBMPs.C_BMP) then
begin
FBMPs.C_BMP.FreeImage;
FreeAndNil(FBMPs.C_BMP);
end;
WList.Free;
end;
procedure TfrmSelList.btnPreviewClick(Sender: TObject);
begin
if (FBMPs.hWindow <> THandle(PWnd(WList.Items[ComboBox1.ItemIndex])^.hWindow)) then
begin
if Assigned(FBMPs.P_BMP) then
FreeAndNil(FBMPs.P_BMP);
if Assigned(FBMPs.D_BMP) then
FreeAndNil(FBMPs.D_BMP);
if Assigned(FBMPs.T_BMP) then
FreeAndNil(FBMPs.T_BMP);
if Assigned(FBMPs.I_BMP) then
FreeAndNil(FBMPs.I_BMP);
if Assigned(FBMPs.G_BMP) then
FreeAndNil(FBMPs.G_BMP);
if Assigned(FBMPs.C_BMP) then
FreeAndNil(FBMPs.C_BMP);
if Assigned(FBMPs.N_BMP) then
FreeAndNil(FBMPs.N_BMP);
FBMPs.Title := PWnd(WList.Items[ComboBox1.ItemIndex])^.Title;
FBMPs.hWindow := PWnd(WList.Items[ComboBox1.ItemIndex])^.hWindow;
if not ScreenShot then exit;
end
else
begin
if not Assigned(FBMPs.N_BMP) then
if not ScreenShot then exit;
end;
if ComboBox2.ItemIndex = 0 then
begin
if not Assigned(FBMPs.P_BMP) then
ShowProg(1)
else
Image1.Picture.Assign(FBMPs.P_BMP);
end
else if ComboBox2.ItemIndex = 1 then
begin
if not Assigned(FBMPs.D_BMP) then
ShowProg(2)
else
Image1.Picture.Assign(FBMPs.D_BMP);
end
else if ComboBox2.ItemIndex = 2 then
begin
if not Assigned(FBMPs.T_BMP) then
ShowProg(3)
else
Image1.Picture.Assign(FBMPs.T_BMP);
end
else if ComboBox2.ItemIndex = 3 then
begin
if not Assigned(FBMPs.G_BMP) then
ShowProg(0)
else
Image1.Picture.Assign(FBMPs.G_BMP);
end
else if ComboBox2.ItemIndex = 4 then
begin
if not Assigned(FBMPs.I_BMP) then
ShowProg(4)
else
Image1.Picture.Assign(FBMPs.I_BMP);
end
else if ComboBox2.ItemIndex = 5 then
begin
if not Assigned(FBMPs.C_BMP) then
ShowProg(5)
else
Image1.Picture.Assign(FBMPs.C_BMP);
end
else
begin
Image1.Picture.Assign(FBMPs.N_BMP);
btnSave.Enabled := True;
end;
{if cmbColor.ItemIndex = 0 then
Mode := 2
else if cmbColor.ItemIndex = 1 then
Mode := 3
else if cmbColor.ItemIndex = 2 then
Mode := 4
else if cmbColor.ItemIndex = 3 then
Mode := 1
else if cmbColor.ItemIndex = 4 then
Mode := 5
else if cmbColor.ItemIndex = 5 then
Mode := 6
else
Mode := 0;
if (cmbColor.ItemIndex = 0) then
begin
if not Assigned(FBMPs.P_BMP) then
ShowProg(Mode - 1)
else
Image1.Picture.Assign(FBMPs.P_BMP);
end
else if (cmbColor.ItemIndex = 1) then
begin
if not Assigned(FBMPs.D_BMP) then
ShowProg(Mode - 1)
else
Image1.Picture.Assign(FBMPs.D_BMP);
end
else if (cmbColor.ItemIndex = 2) then
begin
if not Assigned(FBMPs.T_BMP) then
ShowProg(Mode - 1)
else
Image1.Picture.Assign(FBMPs.T_BMP);
end
else if (cmbColor.ItemIndex = 3) then
begin
if not Assigned(FBMPs.G_BMP) then
ShowProg(Mode - 1)
else
Image1.Picture.Assign(FBMPs.G_BMP);
end
else if (cmbColor.ItemIndex = 4) then
begin
if not Assigned(FBMPs.I_BMP) then
ShowProg(Mode - 1)
else
Image1.Picture.Assign(FBMPs.I_BMP);
end
else if (cmbColor.ItemIndex = 5) then
begin
if not Assigned(FBMPs.C_BMP) then
ShowProg(Mode - 1)
else
Image1.Picture.Assign(FBMPs.C_BMP);
end
else
begin
Image1.Picture.Assign(FBMPs.N_BMP);
btnSave.Enabled := True;
end;}
end;
function TfrmSelList.ScreenShot: boolean;
var
DC: HDC;
RC: TRect;
PT: TPoint;
c:Cardinal;
ires: integer;
begin
Result := False;
try
if GetWindowLong(FBMPs.hWindow, GWL_STYLE) = 0 then
begin
Showmessage(MainForm.GetTranslation('wnd_notfound', 'The selected window cannot be found.'));
ComboBox1.DeleteSelected;
ComboBox1.ItemIndex := 0;
//ListView1.DeleteSelected;
//ListView1.ItemIndex := 0;
Exit;
end;
DC := 0;
if LowerCase(FBMPs.Title) = 'desktop' then
begin
if GetWindowRect(FBMPs.hWindow, RC) then
begin
Hide;
Application.Minimize;
Keybd_event(VK_LWIN, 0, 0, 0);
Keybd_event(Byte('D'), 0, 0, 0);
Keybd_event(Byte('D'), 0, KEYEVENTF_KEYUP, 0);
Keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
c := GetTickCount;
while True do
begin
Application.ProcessMessages;
if GetTickCount - c > 2000 then Break;
end;
DC := GetDC(FBMPs.hWindow);
if DC <> 0 then
begin
try
PT := ScreenToClient(Point(RC.Right, RC.Bottom));
FBMPs.N_BMP := TBitmap.Create;
FBMPs.N_BMP.Width := RC.right-RC.left;
FBMPs.N_BMP.Height := RC.bottom-RC.top;
PT := ScreenToClient(Point(RC.Left, RC.Top));
BitBlt(FBMPs.N_BMP.Canvas.Handle, 0, 0, FBMPs.N_BMP.Width, FBMPs.N_BMP.Height, DC, 0, 0, SRCCOPY);
finally
ReleaseDC(FBMPs.hWindow, DC);
end;
end
else
begin
Application.Restore;
Show;
Showmessage(MainForm.GetTranslation('fail_getdc', Fail_GetDC));
ComboBox1.DeleteSelected;
ComboBox1.ItemIndex := 0;
end;
Keybd_event(VK_LWIN, 0, 0, 0);
Keybd_event(Byte('D'), 0, 0, 0);
Keybd_event(Byte('D'), 0, KEYEVENTF_KEYUP, 0);
Keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
end;
end
else
begin
iRes := GetWindowLong(FBMPs.hWindow, GWL_STYLE);
if (iRes and WS_MINIMIZE) <> 0 then
begin
ShowWindow(FBMPs.hWindow, SW_RESTORE);
end
else
ShowWindow(FBMPs.hWindow, SW_SHOWNA);
MainForm.SetAbsoluteForegroundWindow(FBMPs.hWindow);
Hide;
Application.Minimize;
c := GetTickCount;
while True do
begin
Application.ProcessMessages;
if GetTickCount - c > 1000 then Break;
end;
if GetWindowRect(FBMPs.hWindow, RC) then
begin
if (RC.Right > 0) and (RC.Bottom > 0) then
begin
DC := GetWindowDC(FBMPs.hWindow);
if DC <> 0 then
begin
try
PT := ScreenToClient(Point(RC.Right, RC.Bottom));
FBMPs.N_BMP := TBitmap.Create;
FBMPs.N_BMP.Width := RC.right-RC.left;
FBMPs.N_BMP.Height := RC.bottom-RC.top;
PT := ScreenToClient(Point(RC.Left, RC.Top));
BitBlt(FBMPs.N_BMP.Canvas.Handle, 0, 0, FBMPs.N_BMP.Width, FBMPs.N_BMP.Height, DC, 0, 0, SRCCOPY);
finally
ReleaseDC(FBMPs.hWindow, DC);
end;
end
else
begin
Application.Restore;
Show;
Showmessage(MainForm.GetTranslation('fail_getdc', Fail_GetDC));
ComboBox1.DeleteSelected;
ComboBox1.ItemIndex := 0;
end;
end
else
begin
Application.Restore;
Show;
ShowMessage(MainForm.GetTranslation('fail_wndsize', Fail_WndSize));
ComboBox1.DeleteSelected;
ComboBox1.ItemIndex := 0;
end;
end;
end;
Application.Restore;
Show;
MainForm.SetAbsoluteForegroundWindow(Handle);
if DC <> 0 then Result := True;
except
on E:Exception do
ShowMessage(E.Message);
end;
end;
procedure TfrmSelList.ShowProg(Mode: integer);
var
frmProg: TfrmProgress;
begin
frmProg := TfrmProgress.Create(self);
try
frmProg.Mode := Mode;
frmProg.BMP.Assign(FBMPs.N_BMP);
if frmProg.ShowModal = mrOK then
begin
Inc(Mode);
if Mode = 1 then
begin
if not Assigned(FBMPs.G_BMP) then
FBMPs.G_BMP := TBitMap.Create;
FBMPs.G_BMP.Handle := frmProg.BMP.ReleaseHandle;
Image1.Picture.Assign(FBMPs.G_BMP);
end
else if Mode = 2 then
begin
if not Assigned(FBMPs.P_BMP) then
FBMPs.P_BMP := TBitMap.Create;
FBMPs.P_BMP.Handle := frmProg.BMP.ReleaseHandle;
Image1.Picture.Assign(FBMPs.P_BMP);
end
else if Mode = 3 then
begin
if not Assigned(FBMPs.D_BMP) then
FBMPs.D_BMP := TBitMap.Create;
FBMPs.D_BMP.Handle := frmProg.BMP.ReleaseHandle;
Image1.Picture.Assign(FBMPs.D_BMP);
end
else if Mode = 4 then
begin
if not Assigned(FBMPs.T_BMP) then
FBMPs.T_BMP := TBitMap.Create;
FBMPs.T_BMP.Handle := frmProg.BMP.ReleaseHandle;
Image1.Picture.Assign(FBMPs.T_BMP);
end
else if Mode = 5 then
begin
if not Assigned(FBMPs.I_BMP) then
FBMPs.I_BMP := TBitMap.Create;
FBMPs.I_BMP.Handle := frmProg.BMP.ReleaseHandle;
Image1.Picture.Assign(FBMPs.I_BMP);
end
else if Mode = 6 then
begin
if not Assigned(FBMPs.C_BMP) then
FBMPs.C_BMP := TBitMap.Create;
FBMPs.C_BMP.Handle := frmProg.BMP.ReleaseHandle;
Image1.Picture.Assign(FBMPs.C_BMP);
end;
btnSave.Enabled := True;
end;
finally
frmProg.BMP.Free;
frmProg.Free;
end;
end;
procedure TfrmSelList.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmSelList.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
if Selected then
begin
if (FBMPs.Title = PWnd(WList.Items[ComboBox1.ItemIndex])^.Title) and (FBMPs.hWindow = THandle(PWnd(WList.Items[ComboBox1.ItemIndex])^.hWindow)) then
begin
if (Assigned(FBMPs.N_BMP)) or (Assigned(FBMPs.P_BMP)) or (Assigned(FBMPs.D_BMP)) or (Assigned(FBMPs.T_BMP)) or
(Assigned(FBMPs.G_BMP)) or (Assigned(FBMPs.I_BMP)) then
btnSave.Enabled := True
else
btnSave.Enabled := False;
end
else
btnSave.Enabled := False;
end;
end;
procedure TfrmSelList.btnSaveClick(Sender: TObject);
var
FN: String;
JPG: TJPEGImage;
begin
if SaveDialog1.Execute then
begin
FN := SaveDialog1.FileName;
if ExtractFileExt(FN) = '' then
begin
if SaveDialog1.FilterIndex = 1 then
FN := FN + '.bmp'
else
FN := FN + '.jpg';
end;
if SaveDialog1.FilterIndex = 1 then
Image1.Picture.Bitmap.SaveToFile(FN)
else
begin
JPG := TJPEGImage.Create;
try
JPG.Smoothing := True;//chkSmooth.Checked;
JPG.Assign(Image1.Picture.Bitmap);
JPG.CompressionQuality := 75;//edtC_Quality.AsInteger;
JPG.SaveToFile(FN);
Application.ProcessMessages;
finally
JPG.Free;
end;
end;
end;
end;
function DoubleToInt(d: double): integer;
begin
SetRoundMode(rmUP);
Result := Trunc(SimpleRoundTo(d));
end;
procedure TfrmSelList.WMDPIChanged(var Message: TMessage);
begin
if (Dx > 0) and (Dy > 0) then
begin
scaleX := Message.WParamLo / Dx;
scaleY := Message.WParamHi / Dy;
ResizeCtrls;
end;
end;
procedure TfrmSelList.ResizeCtrls;
var
sHeight, sWidth, mw: integer;
procedure GetStrSize(Cap: string);
begin
sWidth := DoubleToInt(Canvas.TextWidth(Cap));
sHeight := DoubleToInt(Canvas.TextHeight(Cap));
end;
begin
//GetWindowScale(Handle, Dx, Dy, ScaleX, ScaleY);
Font.Size := DoubleToInt(DefFont * ScaleX);
GetStrSize(Caption);
ComboBox1.ItemHeight := sHeight;
ComboBox2.ItemHeight := sHeight;
ComboBox2.Width := DoubleToInt(150 * ScaleX);
GetStrSize(btnPreview.Caption + ' ');
mw := swidth;
GetStrSize(btnSave.Caption + ' ');
mw := MAX(mw, sWidth);
btnPreview.Height := ComboBox1.Height;
btnPreview.Width := mw;
btnSave.Height := ComboBox1.Height;
btnSave.Width := mw;
gbWndList.Height := DoubleToInt(sHeight * 1.3) + ComboBox1.Height + 5;
gbWndList.Width := ComboBox1.Width + 6;
gbSimulation.Height := gbWndList.Height;
gbSimulation.Width := ComboBox2.Width + btnSave.Width + btnPreview.Width + 12;
Scrollbox2.Height := gbWndList.Height + 8;
gbWndList.Top := 0;
gbSimulation.Top := 0;
ComboBox1.Left := 3;
ComboBox1.Top := sHeight;
gbSimulation.Left := gbWndList.Left + gbWndList.Width + 3;
ComboBox2.Left := 3;
ComboBox2.Top := sHeight;
btnSave.Top := sHeight;
btnSave.Left := ComboBox2.Width + 6;
btnPreview.Top := sHeight;
btnPreview.Left := btnSave.Left + btnSave.Width + 3;
Constraints.MinWidth := gbWndList.Width + gbSimulation.Width + 50;
end;
end.