-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTaskbarUtil.cs
79 lines (68 loc) · 2.58 KB
/
TaskbarUtil.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
#region Using statements
using Microsoft.Win32;
using System;
#endregion Using statements
namespace WeekNumber
{
internal static class TaskbarUtil
{
#region Private registry constants
private const string EXPLORER_ADVANCED_REG_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced";
private const string TASKBAR_SMALL_ICONS_REG_NAME = "TaskbarSmallIcons";
#endregion Private registry constants
#region Internal taskbar method
internal static void ToogleTaskbarIconSize()
{
try
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(EXPLORER_ADVANCED_REG_KEY, true))
{
if (key is null)
{
Message.Show(Resources.FailedToUpdateRegistry);
return;
}
int newValue = Math.Abs(((int)key?.GetValue(TASKBAR_SMALL_ICONS_REG_NAME, 0, RegistryValueOptions.None)) - 1);
key?.SetValue(TASKBAR_SMALL_ICONS_REG_NAME, newValue, RegistryValueKind.DWord);
Log.Info = $"{TASKBAR_SMALL_ICONS_REG_NAME}={(newValue == 0 ? "false" : "true")}";
}
}
catch (Exception ex)
{
Message.Show(Resources.FailedToUpdateRegistry, ex);
return;
}
try
{
if (!NativeMethods.SendNotifyMessage((IntPtr)NativeMethods.HWND_BROADCAST,
NativeMethods.WM_SETTINGCHANGE, UIntPtr.Zero, "TraySettings")) //NOTE: Will only work for English Windows UI locale
{
Message.Show(Resources.FailedToNotifyWindowsOfTaskbarIconSizeChange);
}
}
catch (Exception ex)
{
Message.Show(Resources.FailedToNotifyWindowsOfTaskbarIconSizeChange, ex);
}
}
#endregion Internal taskbar method
#region Internal taskbar function
internal static bool UsingSmallTaskbarButtons()
{
try
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(EXPLORER_ADVANCED_REG_KEY, false))
{
return (int)key?.GetValue(TASKBAR_SMALL_ICONS_REG_NAME, 0, RegistryValueOptions.None) != 0;
}
}
catch (Exception ex)
{
Log.LogCaller();
Log.Error = ex;
}
return true;
}
#endregion Internal taskbar function
}
}