Multipurpose utility for managing Games for Windows - LIVE installs and content. (Mirrored from https://github.com/InvoxiPlayGames/GfWLUtility)
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.InteropServices;
5using System.Security.Principal;
6using System.Text;
7using System.Windows.Forms;
8
9namespace GfWLUtility
10{
11 /// <summary>
12 /// Is a button with the UAC shield
13 /// https://stackoverflow.com/a/16226657
14 /// Modified to remove shield when disabled
15 /// </summary>
16 public class ElevatedButton : Button
17 {
18 /// <summary>
19 /// The constructor to create the button with a UAC shield if necessary.
20 /// </summary>
21 public ElevatedButton()
22 {
23 FlatStyle = FlatStyle.System;
24 EnabledChanged += ElevatedOnEnabledChanged;
25 if (!Program.Elevated && Enabled) ShowShield();
26 }
27
28
29 [DllImport("user32.dll")]
30 private static extern IntPtr
31 SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
32
33 private uint BCM_SETSHIELD = 0x0000160C;
34
35 private void ElevatedOnEnabledChanged(object sender, EventArgs e)
36 {
37 if (!Enabled || Program.Elevated)
38 HideShield();
39 else
40 ShowShield();
41 }
42
43 private void ShowShield()
44 {
45 IntPtr wParam = new IntPtr(0);
46 IntPtr lParam = new IntPtr(1);
47 SendMessage(new HandleRef(this, Handle), BCM_SETSHIELD, wParam, lParam);
48 }
49
50 private void HideShield()
51 {
52 IntPtr wParam = new IntPtr(0);
53 IntPtr lParam = new IntPtr(0);
54 SendMessage(new HandleRef(this, Handle), BCM_SETSHIELD, wParam, lParam);
55 }
56 }
57}