Widow – Diff between revs 11 and 21
?pathlinks?
Rev 11 | Rev 21 | |||
---|---|---|---|---|
1 | using System; |
1 | using System; |
|
2 | using System.Reflection; |
2 | using System.Reflection; |
|
3 | using System.Windows.Forms; |
3 | using System.Windows.Forms; |
|
4 | using Microsoft.Win32; |
4 | using Microsoft.Win32; |
|
5 | |
5 | |
|
6 | namespace Widow |
6 | namespace Widow |
|
7 | { |
7 | { |
|
8 | public static class LaunchOnBoot |
8 | public static class LaunchOnBoot |
|
9 | { |
9 | { |
|
10 | #region Public Methods |
10 | #region Public Methods |
|
11 | |
11 | |
|
12 | /// <summary> |
12 | /// <summary> |
|
13 | /// Enable double buffering for an arbitrary control. |
13 | /// Enable double buffering for an arbitrary control. |
|
14 | /// </summary> |
14 | /// </summary> |
|
15 | /// <param name="control">the control to enable double buffering for</param> |
15 | /// <param name="control">the control to enable double buffering for</param> |
|
16 | /// <returns>true on success</returns> |
16 | /// <returns>true on success</returns> |
|
17 | /// <remarks>Do not enable double buffering on RDP: https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793</remarks> |
17 | /// <remarks>Do not enable double buffering on RDP: https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793</remarks> |
|
18 | public static bool SetDoubleBuffered(this Control control) |
18 | public static bool SetDoubleBuffered(this Control control) |
|
19 | { |
19 | { |
|
20 | if (SystemInformation.TerminalServerSession) |
20 | if (SystemInformation.TerminalServerSession) |
|
21 | { |
21 | { |
|
22 | return false; |
22 | return false; |
|
23 | } |
23 | } |
|
24 | |
24 | |
|
25 | var dgvType = control.GetType(); |
25 | var dgvType = control.GetType(); |
|
26 | var pi = dgvType.GetProperty("DoubleBuffered", |
26 | var pi = dgvType.GetProperty("DoubleBuffered", |
|
27 | BindingFlags.Instance | BindingFlags.NonPublic); |
27 | BindingFlags.Instance | BindingFlags.NonPublic); |
|
28 | if (pi == null) |
28 | if (pi == null) |
|
29 | { |
29 | { |
|
30 | return false; |
30 | return false; |
|
31 | } |
31 | } |
|
32 | |
32 | |
|
33 | pi.SetValue(control, true, null); |
33 | pi.SetValue(control, true, null); |
|
34 | |
34 | |
|
35 | return true; |
35 | return true; |
|
36 | } |
36 | } |
|
37 | |
37 | |
|
38 | public static void Execute(this Control control, Action lambda) |
38 | public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : Control |
|
39 | { |
39 | { |
|
40 | if (control.InvokeRequired) |
40 | if (control.InvokeRequired) |
|
41 | { |
41 | { |
|
42 | control.Invoke((MethodInvoker) lambda.Invoke); |
42 | control.BeginInvoke((MethodInvoker) delegate { action(control); }); |
|
43 | } |
- | ||
44 | else |
43 | return; |
|
45 | { |
- | ||
46 | lambda.Invoke(); |
- | ||
47 | } |
44 | } |
|
- | 45 | |
||
- | 46 | action(control); |
||
48 | } |
47 | } |
|
49 | |
48 | |
|
50 | public static bool Set(bool enable) |
49 | public static bool Set(bool enable) |
|
51 | { |
50 | { |
|
52 | using (var key = Registry.CurrentUser.OpenSubKey |
51 | using (var key = Registry.CurrentUser.OpenSubKey |
|
53 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
52 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
|
54 | { |
53 | { |
|
55 | if (key == null) |
54 | if (key == null) |
|
56 | { |
55 | { |
|
57 | return false; |
56 | return false; |
|
58 | } |
57 | } |
|
59 | |
58 | |
|
60 | switch (enable) |
59 | switch (enable) |
|
61 | { |
60 | { |
|
62 | case true: |
61 | case true: |
|
63 | key.SetValue(Constants.AssemblyName, Assembly.GetEntryAssembly().Location); |
62 | key.SetValue(Constants.AssemblyName, Assembly.GetEntryAssembly().Location); |
|
64 | break; |
63 | break; |
|
65 | default: |
64 | default: |
|
66 | key.DeleteValue(Constants.AssemblyName, false); |
65 | key.DeleteValue(Constants.AssemblyName, false); |
|
67 | break; |
66 | break; |
|
68 | } |
67 | } |
|
69 | } |
68 | } |
|
70 | |
69 | |
|
71 | return true; |
70 | return true; |
|
72 | } |
71 | } |
|
73 | |
72 | |
|
74 | public static bool Get() |
73 | public static bool Get() |
|
75 | { |
74 | { |
|
76 | using (var key = Registry.CurrentUser.OpenSubKey |
75 | using (var key = Registry.CurrentUser.OpenSubKey |
|
77 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
76 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
|
78 | { |
77 | { |
|
79 | return key?.GetValue(Constants.AssemblyName) != null; |
78 | return key?.GetValue(Constants.AssemblyName) != null; |
|
80 | } |
79 | } |
|
81 | } |
80 | } |
|
82 | |
81 | |
|
83 | #endregion |
82 | #endregion |
|
84 | } |
83 | } |
|
85 | } |
84 | } |
|
86 | |
85 | |
|
87 |
|
86 |
|
|
88 | |
87 | |
|
89 | |
88 | |
|
90 | |
89 | |