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
public void Dispose()\r
{\r
ReleaseHdc();\r
+ GC.SuppressFinalize(this);\r
}\r
\r
/// <summary>\r
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
\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.Size = bitmap.Size;\r
- form.BackgroundImage = bitmap;\r
+ form = ss = new SprashScreenLayered();\r
+ form.BackgroundImage = img;\r
} else {\r
form = new Form();\r
- form.Size = bitmap.Size;\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 = 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
#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
[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
}\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