OSDN Git Service

AppliStation-GUI,設定ダイアログのリンクラベルをUAC向けシールドアイコンを使用するよう変更(Windows7でシールドアイコンが4色になってしまう)
authorttp <ttp@users.sourceforge.jp>
Sun, 28 Feb 2010 04:55:07 +0000 (13:55 +0900)
committerttp <ttp@users.sourceforge.jp>
Sun, 28 Feb 2010 04:55:07 +0000 (13:55 +0900)
Vista以降はシステムのUAC向けのシールドアイコンを呼び出すよう変更。
XP以前はSystemIconで代用する(従来のアイコンリソースは削除)。

AppliStation/AppliStation.Util/NativeMethods.cs
AppliStation/UserPrefForm.Designer.cs
AppliStation/UserPrefForm.cs
AppliStation/UserPrefForm.resx

index 2bd8d06..31a2f92 100644 (file)
@@ -342,6 +342,18 @@ namespace AppliStation.Util
                [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
@@ -381,11 +393,13 @@ namespace AppliStation.Util
                /// <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
@@ -401,6 +415,51 @@ namespace AppliStation.Util
                                        button.Image = null;\r
                                }\r
                                button.AutoSize = true;\r
+#if USE_VISTA_EFFECTS\r
+                       }\r
+#endif\r
+               }\r
+               \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
+               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
index 0e71739..9cbf827 100644 (file)
@@ -29,7 +29,6 @@
                private void InitializeComponent()\r
                {\r
                        this.components = new System.ComponentModel.Container();\r
-                       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserPrefForm));\r
                        this.proxyURLLabel = new System.Windows.Forms.Label();\r
                        this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();\r
                        this.buttonsPanel = new System.Windows.Forms.FlowLayoutPanel();\r
                        // reposListTabPage\r
                        // \r
                        this.reposListTabPage.Controls.Add(this.repoTableLayoutPanel);\r
-                       this.reposListTabPage.Location = new System.Drawing.Point(4, 21);\r
+                       this.reposListTabPage.Location = new System.Drawing.Point(4, 22);\r
                        this.reposListTabPage.Name = "reposListTabPage";\r
                        this.reposListTabPage.Padding = new System.Windows.Forms.Padding(3);\r
-                       this.reposListTabPage.Size = new System.Drawing.Size(446, 215);\r
+                       this.reposListTabPage.Size = new System.Drawing.Size(446, 214);\r
                        this.reposListTabPage.TabIndex = 0;\r
                        this.reposListTabPage.Text = "レポジトリ";\r
                        this.reposListTabPage.UseVisualStyleBackColor = true;\r
                        this.repoTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());\r
                        this.repoTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));\r
                        this.repoTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());\r
-                       this.repoTableLayoutPanel.Size = new System.Drawing.Size(440, 209);\r
+                       this.repoTableLayoutPanel.Size = new System.Drawing.Size(440, 208);\r
                        this.repoTableLayoutPanel.TabIndex = 1;\r
                        // \r
                        // repoListCheckedListBox\r
                        this.repoListCheckedListBox.Location = new System.Drawing.Point(3, 15);\r
                        this.repoListCheckedListBox.Name = "repoListCheckedListBox";\r
                        this.repoListCheckedListBox.ScrollAlwaysVisible = true;\r
-                       this.repoListCheckedListBox.Size = new System.Drawing.Size(347, 166);\r
+                       this.repoListCheckedListBox.Size = new System.Drawing.Size(347, 165);\r
                        this.repoListCheckedListBox.TabIndex = 1;\r
                        this.repoListCheckedListBox.SelectedIndexChanged += new System.EventHandler(this.RepoListCheckedListBoxSelectedIndexChanged);\r
                        this.repoListCheckedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.RepoListCheckedListBoxItemCheck);\r
                        this.repoUrlTextBox.Dock = System.Windows.Forms.DockStyle.Fill;\r
                        this.repoUrlTextBox.Enabled = false;\r
                        this.repoUrlTextBox.ImeMode = System.Windows.Forms.ImeMode.Off;\r
-                       this.repoUrlTextBox.Location = new System.Drawing.Point(122, 187);\r
+                       this.repoUrlTextBox.Location = new System.Drawing.Point(122, 186);\r
                        this.repoUrlTextBox.Name = "repoUrlTextBox";\r
                        this.repoUrlTextBox.Size = new System.Drawing.Size(315, 19);\r
                        this.repoUrlTextBox.TabIndex = 3;\r
                        this.repoUrlLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));\r
                        this.repoUrlLabel.AutoSize = true;\r
                        this.repoUrlLabel.Enabled = false;\r
-                       this.repoUrlLabel.Location = new System.Drawing.Point(3, 190);\r
+                       this.repoUrlLabel.Location = new System.Drawing.Point(3, 189);\r
                        this.repoUrlLabel.Name = "repoUrlLabel";\r
                        this.repoUrlLabel.Size = new System.Drawing.Size(113, 12);\r
                        this.repoUrlLabel.TabIndex = 2;\r
                        // networkTabPage\r
                        // \r
                        this.networkTabPage.Controls.Add(this.proxyGroupBox);\r
-                       this.networkTabPage.Location = new System.Drawing.Point(4, 21);\r
+                       this.networkTabPage.Location = new System.Drawing.Point(4, 22);\r
                        this.networkTabPage.Name = "networkTabPage";\r
                        this.networkTabPage.Padding = new System.Windows.Forms.Padding(3);\r
-                       this.networkTabPage.Size = new System.Drawing.Size(446, 215);\r
+                       this.networkTabPage.Size = new System.Drawing.Size(446, 214);\r
                        this.networkTabPage.TabIndex = 1;\r
                        this.networkTabPage.Text = "接続";\r
                        this.networkTabPage.UseVisualStyleBackColor = true;\r
                        this.proxyGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;\r
                        this.proxyGroupBox.Location = new System.Drawing.Point(3, 3);\r
                        this.proxyGroupBox.Name = "proxyGroupBox";\r
-                       this.proxyGroupBox.Size = new System.Drawing.Size(440, 209);\r
+                       this.proxyGroupBox.Size = new System.Drawing.Size(440, 208);\r
                        this.proxyGroupBox.TabIndex = 1;\r
                        this.proxyGroupBox.TabStop = false;\r
                        this.proxyGroupBox.Text = "プロキシサーバー";\r
                        this.proxyTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());\r
                        this.proxyTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());\r
                        this.proxyTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));\r
-                       this.proxyTableLayoutPanel.Size = new System.Drawing.Size(434, 191);\r
+                       this.proxyTableLayoutPanel.Size = new System.Drawing.Size(434, 190);\r
                        this.proxyTableLayoutPanel.TabIndex = 0;\r
                        // \r
                        // proxySameAsIERadioButton\r
                        // \r
                        this.openInternetOptionLinkAdminLabel.AutoSize = true;\r
                        this.proxyTableLayoutPanel.SetColumnSpan(this.openInternetOptionLinkAdminLabel, 2);\r
-                       this.openInternetOptionLinkAdminLabel.Image = ((System.Drawing.Image)(resources.GetObject("openInternetOptionLinkAdminLabel.Image")));\r
-                       this.openInternetOptionLinkAdminLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;\r
                        this.openInternetOptionLinkAdminLabel.LinkColor = System.Drawing.SystemColors.HotTrack;\r
                        this.openInternetOptionLinkAdminLabel.Location = new System.Drawing.Point(23, 34);\r
                        this.openInternetOptionLinkAdminLabel.Name = "openInternetOptionLinkAdminLabel";\r
-                       this.openInternetOptionLinkAdminLabel.Padding = new System.Windows.Forms.Padding(16, 0, 0, 0);\r
-                       this.openInternetOptionLinkAdminLabel.Size = new System.Drawing.Size(222, 12);\r
+                       this.openInternetOptionLinkAdminLabel.Size = new System.Drawing.Size(206, 12);\r
                        this.openInternetOptionLinkAdminLabel.TabIndex = 5;\r
                        this.openInternetOptionLinkAdminLabel.TabStop = true;\r
                        this.openInternetOptionLinkAdminLabel.Text = "管理者権限のインターネットオプションを開く";\r
                        // installTabPage\r
                        // \r
                        this.installTabPage.Controls.Add(this.installTableLayoutPanel);\r
-                       this.installTabPage.Location = new System.Drawing.Point(4, 21);\r
+                       this.installTabPage.Location = new System.Drawing.Point(4, 22);\r
                        this.installTabPage.Name = "installTabPage";\r
                        this.installTabPage.Padding = new System.Windows.Forms.Padding(3);\r
-                       this.installTabPage.Size = new System.Drawing.Size(446, 215);\r
+                       this.installTabPage.Size = new System.Drawing.Size(446, 214);\r
                        this.installTabPage.TabIndex = 2;\r
                        this.installTabPage.Text = "インストール";\r
                        this.installTabPage.UseVisualStyleBackColor = true;\r
                        this.installTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());\r
                        this.installTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());\r
                        this.installTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));\r
-                       this.installTableLayoutPanel.Size = new System.Drawing.Size(440, 209);\r
+                       this.installTableLayoutPanel.Size = new System.Drawing.Size(440, 208);\r
                        this.installTableLayoutPanel.TabIndex = 1;\r
                        // \r
                        // installScanInstallerFileCheckbox\r
index 9478094..5b32a77 100644 (file)
@@ -27,6 +27,7 @@ namespace AppliStation
                        InitializeComponent();\r
                        \r
                        this.openInternetOptionLinkAdminLabel.Visible = ! NaGet.Utils.IsAdministrators();\r
+                       AppliStation.Util.NativeMethods.LinkLabel_SetElevationRequiredState(this.openInternetOptionLinkAdminLabel, true);\r
                        \r
                        loadCurrentPref();\r
                }\r
index f3671ce..60c3fcf 100644 (file)
   <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
     <value>17, 17</value>\r
   </metadata>\r
-  <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />\r
-  <data name="openInternetOptionLinkAdminLabel.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">\r
-    <value>\r
-        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8\r
-        YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAApdJREFUOE+Fk21I\r
-        k1EUx61vgRX0wYqc4mi+JOqoD4WV9oJKpC5fM6m1QKdJEpVCTZFCmpl92FaNEicJlWUffGtEy2eS5sbQ\r
-        9mIlFRWIIk60TZuYpPt37mgy6QEf+MPl3P/53XPPc+66IJ5PqVRGBwcHv/B6vSLaXk/fiMfjSVMoFE4+\r
-        /0qMEqNaWlpadTrdvNFohM1m84mtGxsbPbTXRp7I/yAULFSr1d9UKpXHZDKBafnDEJaeNaPpkQzlHfmw\r
-        WCy+OHnmNRqNneUEnjxhtVq97DT342YsDvRg8XU7FjQ3Uf8wAyVdWSh6KkGe5qivIvKCAO5AwIzdbseP\r
-        qmuYuV2Dn1olZq9XwC3Nw+VbeyF5nozM5v1IvbMb+xRRPggB5lYBWHD0ghyTFcWYKMrBZOIeOAUCyKp3\r
-        IuZBBBJUYRDf2AFh+WZewDSrYKr0NGZl6ZiKDYUrKAi/SKcUEdhyPxzRd0VIaBAhrHIbL2DM4XDgo7QQ\r
-        X9KOwBqyHcMbt+JzaCTOV+3CwdZ4HH8ihkSXgCRlmB8wFniFDqrAmyVrQsGZe8jMrcehjAak5KvRbZDD\r
-        8TURw58OY3goGe9fRsFsNi9TD14FAmoMBsOfpKscQuRGhF7isKGkB5vK3qCvrxxwpwLOE8BoOtAXC71e\r
-        P0OA2hVAXV1djFarHWeNFEk7ESfvRPi5TgiLu2B5R4CpY8B4LjBC16NfSN7vBBCuGigK2FgjcyrbIDrb\r
-        jQhpF4RFepj6CeDMBsYkcA0c8M+AgW8aBQRxsSqyq/SIL+MgvshhoP8K4CrF3EiBv3nT5BPwvgnaOEn6\r
-        zSBsbFNqzRgcrPat/w3PIvOs9aAYZKG3t3flMXEcxyZvYc1kP5mMcSQzaYnEkt+SYvhO/gusfu3mrz6d\r
-        pwAAAABJRU5ErkJggg==\r
-</value>\r
-  </data>\r
+  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
+    <value>17, 17</value>\r
+  </metadata>\r
   <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
     <value>104, 17</value>\r
   </metadata>\r