-
Notifications
You must be signed in to change notification settings - Fork 7
/
ShellDir.Manager.pas
172 lines (148 loc) · 3.67 KB
/
ShellDir.Manager.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
unit ShellDir.Manager;
interface
uses
Vcl.Forms, System.Classes, System.SysUtils, Vcl.Dialogs, Winapi.Windows,
System.Generics.Collections, ShellDir.Form, ShellDir.Settings,
HGM.Common.Settings, Vcl.Controls;
type
TListOfWindow = class(TList<TFormPanel>)
function Add: TFormPanel;
end;
TManager = class
private
FWindows: TListOfWindow;
FSettings: TSettingsReg;
function GetGUID: string;
procedure SetSettings(const Value: TSettingsReg);
public
constructor Create;
destructor Destroy;
procedure Run;
procedure Load;
procedure Save;
procedure SetFormsOnTaskBar(Value: Boolean);
property Settings: TSettingsReg read FSettings write SetSettings;
end;
var
Manager: TManager;
implementation
{ TManager }
constructor TManager.Create;
begin
FWindows := TListOfWindow.Create;
FSettings := TSettingsReg.Create(rrHKCU, 'Software\ShellDir');
end;
destructor TManager.Destroy;
begin
FWindows.Clear;
FWindows.Free;
end;
function TManager.GetGUID: string;
var
FG: Integer;
begin
FG := FSettings.GetInt('General', 'GUID', 0);
Inc(FG);
FSettings.SetInt('General', 'GUID', FG);
Result := 'Window_' + FG.ToString;
end;
procedure TManager.Load;
var
List: TStringList;
i: Integer;
begin
List := TStringList.Create;
if FSettings.GetSections('Windows', List) then
begin
for i := 0 to List.Count - 1 do
begin
FWindows.Add.ID := List[i];
end;
end;
List.Free;
if FWindows.Count = 0 then
begin
FWindows.Add.ID := GetGUID;
end;
end;
procedure TManager.Run;
var
i: Integer;
begin
Load;
for i := 0 to FWindows.Count - 1 do
begin
FWindows[i].Show;
end;
end;
procedure TManager.Save;
begin
end;
procedure ChangeAppWindow(const Handle: THandle; const SetAppWindow, RestoreVisibility: Boolean);
var
Style: Integer;
WasVisible, WasIconic: Boolean;
begin
Style := GetWindowLong(Handle, GWL_EXSTYLE);
if (SetAppWindow and (Style and WS_EX_APPWINDOW = 0)) or (not SetAppWindow and (Style and WS_EX_APPWINDOW = WS_EX_APPWINDOW)) then
begin
WasIconic := Winapi.Windows.IsIconic(Handle);
WasVisible := IsWindowVisible(Handle);
if WasVisible or WasIconic then
ShowWindow(Handle, SW_HIDE);
if SetAppWindow then
SetWindowLong(Handle, GWL_EXSTYLE, Style or WS_EX_APPWINDOW)
else
SetWindowLong(Handle, GWL_EXSTYLE, Style and not WS_EX_APPWINDOW);
if (RestoreVisibility and WasVisible) or WasIconic then
begin
if WasIconic then
ShowWindow(Handle, SW_MINIMIZE)
else
ShowWindow(Handle, SW_SHOW);
end;
end;
end;
procedure TManager.SetFormsOnTaskBar(Value: Boolean);
var
i: Integer;
begin
for i := 0 to FWindows.Count - 1 do
begin
if Value then
begin
ChangeAppWindow(FWindows[i].Handle, False, False);
end
else
begin
ChangeAppWindow(FWindows[i].Handle, True, True);
end;
// Recreate Main form to ensure correct owner
FWindows[i].Perform(CM_RECREATEWND, 0, 0);
if Value then
begin
SetWindowLong(FWindows[i].Handle, GWL_EXSTYLE, GetWindowLong(FWindows[i].Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
SetWindowText(FWindows[i].Handle, nil)
end
else
begin
SetWindowLong(FWindows[i].Handle, GWL_EXSTYLE, GetWindowLong(FWindows[i].Handle, GWL_EXSTYLE) and not WS_EX_TOOLWINDOW);
SetWindowText(FWindows[i].Handle, FWindows[i].Caption);
end;
end;
end;
procedure TManager.SetSettings(const Value: TSettingsReg);
begin
FSettings := Value;
end;
{ TListOfWindow }
function TListOfWindow.Add: TFormPanel;
begin
Result := TFormPanel.Create(Application);
inherited Add(Result);
end;
initialization
Manager := TManager.Create;
finalization
Manager.Free;
end.