/
TaskbarSettingsController.cs
483 lines (446 loc) · 20.9 KB
/
TaskbarSettingsController.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Security.AccessControl;
namespace Taskbar11.Controllers
{
/// <summary>
/// Bind actions to the UI-views for TaskbarSettingsView.
/// </summary>
public static class TaskbarSettingsController
{
private const String PathExplorerStuckRects3 = @"Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3";
private const String PathExplorerAdvanced = @"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced";
private const String PathSearch = @"Software\Microsoft\Windows\CurrentVersion\Search";
private const String PathPenWorkspace = @"Software\Microsoft\Windows\CurrentVersion\PenWorkspace";
private const String PathTabletTip = @"Software\Microsoft\TabletTip\1.7";
private const String PathTouchpad = @"Software\Microsoft\Touchpad";
private const String PathExplorerMMStuckRects3 = @"Software\Microsoft\Windows\CurrentVersion\Explorer\MMStuckRects3";
private const String PathInprocServer32 = @"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32";
private const String PathCLSID = @"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}";
private const String ValueKeySettings = "Settings";
private const String ValueKeyTaskbarSize = "TaskbarSi";
private const String ValueKeyTaskbarAlignment = "TaskbarAl";
private const String ValueKeySearchboxTaskbarMode = "SearchboxTaskbarMode";
private const String ValueKeyShowTaskViewButton = "ShowTaskViewButton";
private const String ValueKeyTaskbarWidgets = "TaskbarDa";
private const String ValueKeyTaskbarChat = "TaskbarMn";
private const String ValueKeyPenWorkspace = "PenWorkspaceButtonDesiredVisibility";
private const String ValueKeyTouchKeyboard = "TipbandDesiredVisibility";
private const String ValueKeyTouchpad = "TouchpadDesiredVisibility";
private const String ValueKeyMultiMonitorTaskbar = "MMTaskbarEnabled";
/// <summary>
/// Read the taskbar position from the registry.
/// </summary>
/// <returns>Integer that specifies the taskbar position on index 12 of the "Settings" key.</returns>
public static int GetTaskbarPosition()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerStuckRects3, true);
if (key != null)
{
Object value = key.GetValue(ValueKeySettings);
if (value != null)
{
Byte[] data = (Byte[])value;
return data[7 + 5];
}
}
return -1;
}
/// <summary>
/// Write the taskbar position to the registry.
/// </summary>
/// <param name="taskbarPosition">Byte that specifies the taskbar position on index 12 of the "Settings" key.</param>
public static void SetTaskbarPosition(Byte taskbarPosition)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerStuckRects3, true);
if (key != null)
{
Object value = key.GetValue(ValueKeySettings);
if (value != null)
{
Byte[] data = (Byte[])value;
data[7 + 5] = taskbarPosition;
key.SetValue(ValueKeySettings, data, RegistryValueKind.Binary);
}
}
}
/// <summary>
/// Read the taskbar size from the registry.
/// </summary>
/// <returns>Integer that specifies the taskbar size.</returns>
public static int GetTaskbarSize()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyTaskbarSize);
if (value != null)
return (int)value;
}
return -1;
}
/// <summary>
/// Write the taskbar size to the registry.
/// </summary>
/// <param name="taskbarSize">Byte that specifies the taskbar size.</param>
public static void SetTaskbarSize(Byte taskbarSize)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
key.SetValue(ValueKeyTaskbarSize, taskbarSize, RegistryValueKind.DWord);
}
/// <summary>
/// Read the taskbar aligment from the registry.
/// </summary>
/// <returns>Integer that specifies the taskbar aligment.</returns>
public static int GetTaskbarAlignment()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyTaskbarAlignment);
if (value != null)
return (int)value;
}
return -1;
}
/// <summary>
/// Write the taskbar alignment to the registry.
/// </summary>
/// <param name="taskbarAlignment">Byte that specifies the taskbar alignment.</param>
public static void SetTaskbarAlignment(Byte taskbarAlignment)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
key.SetValue(ValueKeyTaskbarAlignment, taskbarAlignment, RegistryValueKind.DWord);
}
/// <summary>
/// Read the SearchboxTaskbarMode property from the registry.
/// </summary>
/// <returns>Boolean that defines whether the Search button is visible on the taskbar.</returns>
public static Boolean IsTaskbarSearchVisible()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathSearch, true);
if (key != null)
{
Object value = key.GetValue(ValueKeySearchboxTaskbarMode);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the taskbar SearchboxTaskbarMode property to the registry.
/// </summary>
/// <param name="isVisible">Boolean that defines whether the Search button is visible on the taskbar.</param>
public static void SetTaskbarSearchVisible(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathSearch, true);
if (key != null)
key.SetValue(ValueKeySearchboxTaskbarMode, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the ShowTaskViewButton property from the registry.
/// </summary>
/// <returns>Boolean that defines whether the TaskView button is visible on the taskbar.</returns>
public static Boolean IsTaskbarTaskViewVisible()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyShowTaskViewButton);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the taskbar ShowTaskViewButton property to the registry.
/// </summary>
/// <param name="isVisible">Boolean that defines whether the TaskView button is visible on the taskbar.</param>
public static void SetTaskbarTaskViewVisible(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
key.SetValue(ValueKeyShowTaskViewButton, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the TaskbarDa property from the registry.
/// </summary>
/// <returns>Boolean that defines whether the Widgets button is visible on the taskbar.</returns>
public static Boolean IsTaskbarWidgetsVisible()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyTaskbarWidgets);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the taskbar TaskbarDa property to the registry.
/// </summary>
/// <param name="isVisible">Boolean that defines whether the Widgets button is visible on the taskbar.</param>
public static void SetTaskbarWidgetsVisible(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
key.SetValue(ValueKeyTaskbarWidgets, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the TaskbarMn property from the registry.
/// </summary>
/// <returns>Boolean that defines whether the Chat button is visible on the taskbar.</returns>
public static Boolean IsTaskbarChatVisible()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyTaskbarChat);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the taskbar TaskbarMn property to the registry.
/// </summary>
/// <param name="isVisible">Boolean that defines whether the Chat button is visible on the taskbar.</param>
public static void SetTaskbarChatVisible(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
key.SetValue(ValueKeyTaskbarChat, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the PenWorkspaceButtonDesiredVisibility property from the registry.
/// </summary>
/// <returns>Boolean that defines whether the Pen button is visible on the taskbar.</returns>
public static Boolean IsTaskbarPenVisible()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathPenWorkspace, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyPenWorkspace);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the taskbar PenWorkspaceButtonDesiredVisibility property to the registry.
/// </summary>
/// <param name="isVisible">Boolean that defines whether the Pen button is visible on the taskbar.</param>
public static void SetTaskbarPenVisible(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathPenWorkspace, true);
if (key != null)
key.SetValue(ValueKeyPenWorkspace, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the TipbandDesiredVisibility property from the registry.
/// </summary>
/// <returns>Boolean that defines whether the Touch Keyboard button is visible on the taskbar.</returns>
public static Boolean IsTaskbarTouchKeyboardVisible()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathTabletTip, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyTouchKeyboard);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the taskbar TipbandDesiredVisibility property to the registry.
/// </summary>
/// <param name="isVisible">Boolean that defines whether the Touch Keyboard button is visible on the taskbar.</param>
public static void SetTaskbarTouchKeyboardVisible(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathTabletTip, true);
if (key != null)
key.SetValue(ValueKeyTouchKeyboard, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the TouchpadDesiredVisibility property from the registry.
/// </summary>
/// <returns>Boolean that defines whether the Touchpad button is visible on the taskbar.</returns>
public static Boolean IsTaskbarTouchpadVisible()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathTouchpad, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyTouchpad);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the TouchpadDesiredVisibility property to the registry.
/// </summary>
/// <param name="isVisible">Boolean that defines whether the Touchpad button is visible on the taskbar.</param>
public static void SetTaskbarTouchpadVisible(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathTouchpad, true);
if (key != null)
key.SetValue(ValueKeyTouchpad, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the Settings property from the registry.
/// </summary>
/// <returns>Boolean that specifies whether the taskbar automatically hides based on index 8 of the "Settings" key.</returns>
public static Boolean IsTaskbarHidden()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerStuckRects3, true);
if (key != null)
{
Object value = key.GetValue(ValueKeySettings);
if (value != null)
{
Byte[] data = (Byte[])value;
return data[7 + 1] == 123;
}
}
return false;
}
/// <summary>
/// Write the Settings property to the registry.
/// </summary>
/// <param name="taskbarPosition">Boolean that specifies whether the taskbar automatically hides based on index 8 of the "Settings" key.</param>
public static void SetTaskbarHides(Boolean isTaskbarHidden)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerStuckRects3, true);
if (key != null)
{
Object value = key.GetValue(ValueKeySettings);
if (value != null)
{
Byte[] data = (Byte[])value;
data[7 + 1] = (Byte)(isTaskbarHidden ? 123 : 122);
key.SetValue(ValueKeySettings, data, RegistryValueKind.Binary);
}
}
}
/// <summary>
/// Read the MMTaskbarEnabled property from the registry
/// </summary>
/// <returns>Boolean that specifies whether the taskbar is shown on multiple monitors.</returns>
public static Boolean IsTaskbarOnMultipleMonitors()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
{
Object value = key.GetValue(ValueKeyMultiMonitorTaskbar);
if (value != null)
return ((int)value) == 1;
}
return false;
}
/// <summary>
/// Write the MMTaskbarEnabled property to the register.
/// </summary>
/// <param name="isVisible">Boolean that specifies whether the taskbar is shown on multiple monitors.</param>
public static void SetTaskbarOnMultipleMonitors(Boolean isVisible)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerAdvanced, true);
if (key != null)
key.SetValue(ValueKeyMultiMonitorTaskbar, isVisible ? 1 : 0, RegistryValueKind.DWord);
}
/// <summary>
/// Read the monitor visibility settings from the registry.
/// </summary>
/// <returns>Boolean that specifies the Multi Monitor Taskbar Behaviour, based on index 12 of each display key.</returns>
public static Boolean IsTaskbarMultiMonitorPositionTaskbar()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerMMStuckRects3, true);
if (key != null)
{
Byte displayCount = 0;
foreach (String keyName in key.GetValueNames())
{
if (key.GetValueKind(keyName) == RegistryValueKind.Binary)
{
displayCount++;
Object value = key.GetValue(keyName);
if (value != null)
{
Byte[] data = (Byte[])value;
if (data[7 + 5] != GetTaskbarPosition()) return false;
}
}
}
if (displayCount < 2) return false;
return true;
}
return false;
}
/// <summary>
/// Write the monitor visibility settings to the registry.
/// </summary>
/// <param name="multiMonitorTaskbarPosition">Boolean that specifies the Multi Monitor Taskbar Behaviour, based on index 12 of each display key.</param>
public static void SetTaskbarMultiMonitorPosition(Boolean multiMonitorTaskbarPosition)
{
if (!multiMonitorTaskbarPosition) return;
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathExplorerMMStuckRects3, true);
if (key != null)
{
foreach (String keyName in key.GetValueNames())
{
if (key.GetValueKind(keyName) == RegistryValueKind.Binary)
{
Object value = key.GetValue(keyName);
if (value != null)
{
Byte[] data = (Byte[])value;
data[7 + 5] = (Byte)GetTaskbarPosition();
key.SetValue(keyName, data, RegistryValueKind.Binary);
}
}
}
}
}
/// <summary>
/// Check whether a specific key is present on the system, this determines whether the old context menu is being used.
/// </summary>
/// <returns>Boolean that defines whether the old context menu is used.</returns>
public static Boolean IsUseOldContextMenu()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathInprocServer32, true);
if (key == null) return false;
else return (key.GetValue(String.Empty) == String.Empty);
}
/// <summary>
/// Write settings for the context menu to the registry.
/// </summary>
/// <param name="useOldContextMenu">Boolean that defines whether the old context menu is used.</param>
public static void SetUseOldContextMenu(Boolean useOldContextMenu)
{
RegistrySecurity registrySecurity = new RegistrySecurity();
registrySecurity.SetAccessRule(new RegistryAccessRule(Environment.UserDomainName + "\\" + Environment.UserName, RegistryRights.FullControl, AccessControlType.Allow));
RegistryKey clsidKey = Registry.CurrentUser.OpenSubKey(PathCLSID, true);
RegistryKey key = Registry.CurrentUser.OpenSubKey(PathInprocServer32, true);
if (clsidKey == null)
{
Registry.CurrentUser.CreateSubKey(PathCLSID, RegistryKeyPermissionCheck.Default);
clsidKey = Registry.CurrentUser.OpenSubKey(PathCLSID, true);
}
if (key == null)
{
Registry.CurrentUser.CreateSubKey(PathInprocServer32, RegistryKeyPermissionCheck.Default);
key = Registry.CurrentUser.OpenSubKey(PathInprocServer32, true);
}
clsidKey.SetAccessControl(registrySecurity);
if (useOldContextMenu)
key.SetValue(String.Empty, String.Empty);
else if (clsidKey != null)
Registry.CurrentUser.DeleteSubKeyTree(PathInprocServer32);
}
}
}