Exemple #1
0
 private void OnPaint(object sender, PaintEventArgs e)
 {
     if (_dwmComposited)
     {
         var rc = new Rectangle(0, ClientSize.Height - 35,
                                ClientSize.Width, 35);
         IntPtr destdc    = e.Graphics.GetHdc();
         IntPtr memdc     = WindowsApi.CreateCompatibleDC(destdc);
         IntPtr bitmapOld = IntPtr.Zero;
         var    dib       = new BitmapInfo {
             biHeight      = -(rc.Bottom - rc.Top),
             biWidth       = rc.Right - rc.Left,
             biPlanes      = 1,
             biSize        = Marshal.SizeOf(typeof(BitmapInfo)),
             biBitCount    = 32,
             biCompression = 0
         };
         if (WindowsApi.SaveDC(memdc) != 0)
         {
             IntPtr tmp;
             IntPtr bitmap = WindowsApi.CreateDIBSection(memdc, ref dib,
                                                         0, out tmp,
                                                         IntPtr.Zero, 0);
             if (!(bitmap == IntPtr.Zero))
             {
                 bitmapOld = WindowsApi.SelectObject(memdc, bitmap);
                 WindowsApi.BitBlt(destdc, rc.Left, rc.Top,
                                   rc.Right - rc.Left, rc.Bottom - rc.Top,
                                   memdc, 0, 0,
                                   CopyPixelOperation.SourceCopy);
             }
             WindowsApi.SelectObject(memdc, bitmapOld);
             WindowsApi.DeleteObject(bitmap);
             WindowsApi.DeleteDC(memdc);
         }
         e.Graphics.ReleaseHdc(destdc);
     }
     e.Graphics.DrawImage(_ssButtonImage,
                          new Rectangle(ssButton.Location, ssButton.Size));
 }