-
Notifications
You must be signed in to change notification settings - Fork 5
/
frmDarkOverlay.pas
95 lines (83 loc) · 2.35 KB
/
frmDarkOverlay.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
unit frmDarkOverlay;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
const
WM_RESIZEEVENT = WM_USER + 12;
type
TformDarker = class(TForm)
Shape1: TShape;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure ResizeEvent(var Msg: TMessage); message WM_RESIZEEVENT;
public
{ Public declarations }
end;
var
formDarker: TformDarker;
implementation
uses
DwmApi;
{$R *.dfm}
procedure TformDarker.FormCreate(Sender: TObject);
var
res: Integer;
begin
DoubleBuffered := True;
Shape1.Pen.Style := psClear;
BorderStyle := bsNone;
Color := clBlack;
WindowState := wsMaximized;
FormStyle := fsStayOnTop;
AlphaBlend := True;
AlphaBlendValue := 200;
TransparentColor := True;
TransparentColorValue := clWhite;
Shape1.Visible := True;
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TRANSPARENT or WS_EX_TOOLWINDOW);
if DwmCompositionEnabled then
DwmSetWindowAttribute(Handle, DWMWA_EXCLUDED_FROM_PEEK or DWMWA_FLIP3D_POLICY, @res, SizeOf(Integer));
end;
procedure TformDarker.FormShow(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure TformDarker.ResizeEvent(var Msg: TMessage);
var
r,s: TRect;
fw: HWND;
begin
fw := GetForegroundWindow;
if fw <> 0 then
begin
if IsWindow(fw) then
begin
GetWindowRect(fw, s);
Winapi.Windows.GetClientRect(fw, r);
// case BorderStyle of
// bsSingle:
// Result := GetSystemMetrics(SM_CYFIXEDFRAME);
//
// bsDialog, bsToolWindow:
// Result := GetSystemMetrics(SM_CYDLGFRAME);
//
// bsSizeable, bsSizeToolWin:
// Result := GetSystemMetrics(SM_CYSIZEFRAME) +
// GetSystemMetrics(SM_CXPADDEDBORDER);
// else
// Result := 0;
// end;
Shape1.Left := s.Left + (s.Width - r.Width) div 2;
Shape1.Top := s.Top + (GetSystemMetrics(SM_CYFIXEDFRAME)) div 2;
Shape1.Width := r.Width;
if GetWindowLong(fw, GWL_STYLE) and WS_CAPTION <> WS_CAPTION then
Shape1.Height := s.Height
else
Shape1.Height := s.Height - (GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER));
end;
end;
end;
end.