OSDN Git Service

AppliStation,チケット #23338 AVGをアンインストールしようとするとエラーが発生してしまう 対策
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / SprashScreenLayered.cs
index aa3da3f..75e57c5 100644 (file)
@@ -56,7 +56,10 @@ namespace AppliStation.Util
                public void ReleaseHdc()\r
                {\r
                        if (this.isGottenDc) { // GetDC 関数を使って取得した場合\r
-                               ReleaseDC(hWnd, hDc);\r
+                               int result = ReleaseDC(hWnd, hDc);\r
+                               if (result != 1) {\r
+                                       throw new System.ComponentModel.Win32Exception();\r
+                               }\r
                        } else {\r
                                DeleteObject(hDc);\r
                        }\r
@@ -65,6 +68,7 @@ namespace AppliStation.Util
                public void Dispose()\r
                {\r
                        ReleaseHdc();\r
+                       GC.SuppressFinalize(this);\r
                }\r
                \r
                /// <summary>\r
@@ -95,6 +99,7 @@ namespace AppliStation.Util
                private static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);\r
                \r
                [DllImport("gdi32.dll")]\r
+               [return: MarshalAs(UnmanagedType.Bool)]\r
                private static extern bool DeleteObject(IntPtr hObject);\r
                \r
                #endregion\r
@@ -102,26 +107,27 @@ namespace AppliStation.Util
        \r
        public class SprashScreenLayered : Form\r
        {\r
-               public static Form CreateSprashScreenLayered(Bitmap bitmap, Color bgColor)\r
+               public static Form CreateSprashScreenLayered(Image img, Color bgColor)\r
                {\r
                        Form form;\r
+                       SprashScreenLayered ss = null;\r
                        \r
                        if (OSFeature.Feature.IsPresent(OSFeature.LayeredWindows)) {\r
-                               form = new SprashScreenLayered();\r
-                               form.BackgroundImage = bitmap;\r
+                               form = ss = new SprashScreenLayered();\r
+                               form.BackgroundImage = img;\r
                        } else {\r
                                form = new Form();\r
-                               form.BackgroundImage = bitmap;\r
+                               form.BackgroundImage = img;\r
                                form.BackColor = bgColor;\r
                        }\r
                        //form.ShowInTaskbar = false;\r
                        form.ControlBox = false;\r
                        form.FormBorderStyle = FormBorderStyle.None;\r
                        form.StartPosition = FormStartPosition.CenterScreen;\r
-                       form.Size = bitmap.Size;\r
+                       form.Size = img.Size;\r
                        \r
-                       if (form is SprashScreenLayered) {\r
-                               ((SprashScreenLayered) form).CenterToScreen2();\r
+                       if (ss != null) {\r
+                               ss.CenterToScreen2();\r
                        }\r
                        \r
                        return form;\r
@@ -155,6 +161,7 @@ namespace AppliStation.Util
                #region UpdateLayeredWindow関連\r
                \r
                [DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]\r
+               [return: MarshalAs(UnmanagedType.Bool)]\r
                private static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst,\r
                                                               [In] ref Point pptDst, [In] ref Size psize,\r
                                                               IntPtr hdcSrc, [In] ref Point pptSrc,\r
@@ -162,15 +169,16 @@ namespace AppliStation.Util
                                                               [In] ref BLENDFUNCTION pblend,\r
                                                               uint dwFlags);\r
                \r
-               private Bitmap convertBitmap(Image img)\r
+               private static Bitmap convertBitmap(Image img)\r
                {\r
-                       if (img is Bitmap) {\r
-                               return (Bitmap) img;\r
-                       } else {\r
-                               Bitmap bitmap = new Bitmap(img.Width, img.Height, img.PixelFormat);\r
+                       Bitmap bitmap;\r
+                       \r
+                       bitmap = img as Bitmap;\r
+                       if (bitmap == null) {\r
+                               bitmap = new Bitmap(img.Width, img.Height, img.PixelFormat);\r
                                Graphics.FromImage(bitmap).DrawImage(img, 0, 0);\r
-                               return bitmap;\r
                        }\r
+                       return bitmap;\r
                }\r
                \r
                protected void updateLayeredWindow()\r
@@ -210,7 +218,7 @@ namespace AppliStation.Util
                }\r
                \r
                [StructLayout(LayoutKind.Sequential, Pack=1)]\r
-               protected struct BLENDFUNCTION\r
+               protected internal struct BLENDFUNCTION\r
                {\r
                        public byte BlendOp;\r
                        public byte BlendFlags;\r