コード例 #1
0
 private void SetBackground(Image img)
 {
     try
     {
         Bitmap bitmap = (Bitmap)img;
         if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
         {
             throw new ApplicationException();
         }
         IntPtr hObject = IntPtr.Zero;
         IntPtr zero    = IntPtr.Zero;
         IntPtr hDC     = Win32.GetDC(IntPtr.Zero);
         IntPtr ptr2    = Win32.CreateCompatibleDC(hDC);
         try
         {
             hObject = bitmap.GetHbitmap(Color.FromArgb(0));
             zero    = Win32.SelectObject(ptr2, hObject);
             Win32.Size  size2  = new Win32.Size(bitmap.Width, bitmap.Height);
             Win32.Size  psize  = size2;
             Win32.Point point3 = new Win32.Point(0, 0);
             Win32.Point pprSrc = point3;
             point3 = new Win32.Point(base.Left, base.Top);
             Win32.Point         pptDst = point3;
             Win32.BLENDFUNCTION pblend = new Win32.BLENDFUNCTION();
             pblend.BlendOp             = 0;
             pblend.BlendFlags          = 0;
             pblend.SourceConstantAlpha = 0xff;
             pblend.AlphaFormat         = 1;
             Win32.UpdateLayeredWindow(this.Handle, hDC, ref pptDst, ref psize, ptr2, ref pprSrc, 0, ref pblend, 2);
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             throw exception;
         }
         finally
         {
             Win32.ReleaseDC(IntPtr.Zero, hDC);
             if (hObject != IntPtr.Zero)
             {
                 Win32.SelectObject(ptr2, zero);
                 Win32.DeleteObject(hObject);
             }
             Win32.DeleteDC(ptr2);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
コード例 #2
0
 public Size(int cx, int cy)
 {
     this    = new Win32.Size();
     this.cx = cx;
     this.cy = cy;
 }