[return: MarshalAs(UnmanagedType.Bool)]\r
private static extern bool DestroyIcon(IntPtr hIcon);\r
\r
+ [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]\r
+ private struct SHSTOCKICONINFO\r
+ {\r
+ public Int32 cbSize;\r
+ public IntPtr hIcon;\r
+ public Int32 iSysImageIndex;\r
+ public Int32 iIcon;\r
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)] public string path;\r
+ }\r
+ \r
+ [DllImport("shell32.dll", CharSet=CharSet.Unicode, ExactSpelling=true, SetLastError=true)]\r
+ private static extern void SHGetStockIconInfo(uint siid, uint uFlags, ref SHSTOCKICONINFO sii);\r
\r
/// <summary>\r
/// アイコンファイル(実行ファイル・DLL)を開いてアイコンを作る\r
/// <param name="required">ユーザ昇格が必要か否か、すなわちシールドアイコンを表示するか</param> \r
public static void Button_SetElevationRequiredState(Button button, bool required)\r
{\r
+#if USE_VISTA_EFFECTS\r
if (Environment.OSVersion.Version.Major >= 6) {\r
button.FlatStyle = FlatStyle.System;\r
// SendMessage(hWnd, BCM_SETSHIELD, 0, required);\r
SendMessage(button.Handle, 0x160C, IntPtr.Zero, new IntPtr((required)? 1u : 0u));\r
} else { // Legacy OS\r
+#endif\r
// FlatStyle.System に設定されている場合、Image プロパティに割り当てられているイメージは表示されない対策\r
if (button.FlatStyle == FlatStyle.System) {\r
button.FlatStyle = FlatStyle.Standard;\r
button.Image = null;\r
}\r
button.AutoSize = true;\r
+#if USE_VISTA_EFFECTS\r
+ }\r
+#endif\r
+ }\r
+ \r
+ /// <summary>\r
+ /// シェルのソトックアイコンのハンドラを取得する。\r
+ /// </summary>\r
+ /// <param name="siid">ストックID</param>\r
+ /// <param name="isSmall">アイコンサイズは小さいのであればtrueを指定</param>\r
+ /// <returns>アイコンのハンドラ。存在しない場合、null</returns>\r
+ private static IntPtr SHGetStockIconHandle(uint siid, bool isSmall)\r
+ {\r
+#if USE_VISTA_EFFECTS\r
+ try {\r
+ SHSTOCKICONINFO sii = new SHSTOCKICONINFO();\r
+ sii.cbSize = Marshal.SizeOf(typeof(SHSTOCKICONINFO));\r
+ sii.hIcon = IntPtr.Zero;\r
+ \r
+ //SHGetStockIconInfo(siid, SHGFI_ICON | ((isSmall)? SHGFI_SMALLICON : SHGFI_LARGEICON), ref sii);\r
+ SHGetStockIconInfo(siid, 0x100u | ((isSmall)? 0x1u : 0x0u), ref sii);\r
+ \r
+ return sii.hIcon;\r
+ } catch (Exception) {\r
+ return IntPtr.Zero;\r
+ }\r
+#else\r
+ return IntPtr.Zero;\r
+#endif\r
+ }\r
+ \r
+ /// <summary>\r
+ /// ユーザ昇格が必要か設定し、設定必要なときシールドアイコンを表示する。\r
+ /// </summary>\r
+ /// <param name="label">対象のリンクラベル</param>\r
+ /// <param name="required">ユーザ昇格が必要か否か、すなわちシールドアイコンを表示するか</param> \r
+ public static void LinkLabel_SetElevationRequiredState(LinkLabel label, bool required)\r
+ {\r
+ if (required) {\r
+ IntPtr iconHandle = IntPtr.Zero;\r
+ \r
+ //SHGetStockIconHandle(SIID_SHIELD, true);\r
+ iconHandle = SHGetStockIconHandle(77, true);\r
+ if (iconHandle != IntPtr.Zero) {\r
+ label.Image = Bitmap.FromHicon(iconHandle);\r
+ } else {\r
+ using (Icon ico = new Icon(SystemIcons.Shield, 16, 16)) {\r
+ label.Image = ico.ToBitmap();\r
+ }\r
+ }\r
+ \r
+ label.ImageAlign = ContentAlignment.MiddleLeft;\r
+ label.Padding = new Padding(label.Image.Width, label.Padding.Top, label.Padding.Right, label.Padding.Bottom);\r
+ } else {\r
+ label.Image = null;\r
+ label.Padding = new Padding(0);\r
}\r
}\r
\r