public void Repaint()
        {
            IntPtr DC = WinApi.GetDC(Handle);

            WinApi.BitBlt(DC, 0, 0, Width, Height, bDC, 0, 0, WinApi.SRCCOPY);
            WinApi.ReleaseDC(this.Handle, DC);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            IntPtr    DC = e.Graphics.GetHdc();
            Rectangle r  = e.ClipRectangle;

            WinApi.BitBlt(DC, r.X, r.Y, r.Right, r.Bottom, bDC, r.X, r.Y, WinApi.SRCCOPY);
            e.Graphics.ReleaseHdc();
        }
Exemple #3
0
        private void PaintDoubleBuffered(Graphics wndGraphics, Rectangle clip)
        {
            using (Bitmap bmp = new Bitmap(Width, Height))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.Clear(Color.Black);
                    PaintOn(g, clip);
                    g.Flush();

                    WinApi.BitBlt(wndGraphics.GetHdc(), clip.X, clip.Y, clip.Width, clip.Height, g.GetHdc(), clip.X, clip.Y, WinApi.SRCCOPY);
                    //WinApi.BitBlt(wndGraphics.GetHdc(), 0, 0, Width, Height, g.GetHdc(), 0, 0, WinApi.SRCCOPY);
                }

                //wndGraphics.DrawImage(bmp, Point.Empty);
            }
        }
Exemple #4
0
        public static Bitmap GetBitmapWindowClient(IntPtr handle)
        {
            try
            {
                // get te hDC of the target window
                IntPtr hdcSrc = WinApi.GetWindowDC(handle);
                // get the size
                //RECT windowRect;
                //WinApi.GetWindowRect(handle, out windowRect);
                //int width = windowRect.Right - windowRect.Left;
                //int height = windowRect.Bottom - windowRect.Top;

                Rectangle rw     = WinApi.GetWindowRectangle(handle);
                Rectangle rc     = WinApi.GetClientRectangle(handle);
                int       width  = rc.Right - rc.Left;
                int       height = rc.Bottom - rc.Top;
                // create a device context we can copy to
                IntPtr hdcDest = WinApi.CreateCompatibleDC(hdcSrc);
                // create a bitmap we can copy it to,
                // using GetDeviceCaps to get the width/height
                IntPtr hBitmap = WinApi.CreateCompatibleBitmap(hdcSrc, width, height);
                // select the bitmap object
                IntPtr hOld = WinApi.SelectObject(hdcDest, hBitmap);
                // bitblt over
                WinApi.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, rc.X - rw.X, rc.Y - rw.Y, WinApi.SRCCOPY);
                // restore selection
                WinApi.SelectObject(hdcDest, hOld);
                // clean up
                WinApi.DeleteDC(hdcDest);
                WinApi.ReleaseDC(handle, hdcSrc);
                Bitmap bitmap = System.Drawing.Image.FromHbitmap(hBitmap);
                // free up the Bitmap object
                WinApi.DeleteObject(hBitmap);

                return(bitmap);
            }
            catch (Exception)
            {
                return(null);
            }
        }