Exemple #1
0
        public static IntPtr Capture(IntPtr windowHandle, int x, int y, int width, int height)
        {
            if (width < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(width));
            }
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(height));
            }
            if (width == 0 || height == 0)
            {
                return(IntPtr.Zero);
            }
            IntPtr hSource        = Window.GetWindowDC(windowHandle);
            IntPtr hMemory        = GDI.CreateCompatibleDC(hSource);
            IntPtr hBitmap        = GDI.CreateCompatibleBitmap(hSource, width, height);
            IntPtr hPrimaryBitmap = GDI.SelectObject(hMemory, hBitmap);

            GDI.BitBlt(hMemory, 0, 0, width, height, hSource, x, y, GDI.RasterOperationCodes.SRCCOPY);
            GDI.SelectObject(hMemory, hPrimaryBitmap);
            GDI.DeleteDC(hMemory);
            Window.ReleaseDC(windowHandle, hSource);
            return(hBitmap);
        }
Exemple #2
0
        public void UpdateView()
        {
            if ((FUpdateCount == 0) && IsHandleCreated)
            {
                if (FMemDC != IntPtr.Zero)
                {
                    GDI.DeleteDC(FMemDC);
                }
                FMemDC = (IntPtr)GDI.CreateCompatibleDC(FDC);

                int    vViewWidth  = GetViewWidth();
                int    vViewHeight = GetViewHeight();
                IntPtr vBitmap     = (IntPtr)GDI.CreateCompatibleBitmap(FDC, vViewWidth, vViewHeight);
                GDI.SelectObject(FMemDC, vBitmap);
                try
                {
                    using (HCCanvas vDataBmpCanvas = new HCCanvas(FMemDC))
                    {
                        // 控件背景
                        vDataBmpCanvas.Brush.Color = Color.White;// $00E7BE9F;
                        vDataBmpCanvas.FillRect(new RECT(0, 0, vViewWidth, vViewHeight));

                        PaintInfo vPaintInfo = new PaintInfo();
                        try
                        {
                            FData.PaintData(this.Padding.Left - FHScrollBar.Position, // 当前页数据要绘制到的Left
                                            this.Padding.Top,                         // 当前页数据要绘制到的Top
                                            this.Width - FHScrollBar.Position - this.Padding.Right,
                                            this.Padding.Top + FData.Height,          // 当前页数据要绘制的Bottom
                                            this.Padding.Top,                         // 界面呈现当前页数据的Top位置
                                            this.Height - FHScrollBar.Height,         // 界面呈现当前页数据Bottom位置
                                            FVScrollBar.Position,                     // 指定从哪个位置开始的数据绘制到页数据起始位置
                                            vDataBmpCanvas,
                                            vPaintInfo);

                            for (int i = 0; i <= vPaintInfo.TopItems.Count - 1; i++)  // 绘制顶层Ite
                            {
                                vPaintInfo.TopItems[i].PaintTop(vDataBmpCanvas);
                            }
                        }
                        finally
                        {
                            vPaintInfo.Dispose();
                        }

                        GDI.BitBlt(FDC, 0, 0, vViewWidth, vViewHeight, FMemDC, 0, 0, GDI.SRCCOPY);
                    }
                }
                finally
                {
                    GDI.DeleteObject(vBitmap);
                }

                RECT vRect = new RECT(0, 0, vViewWidth, vViewHeight);
                User.InvalidateRect(this.Handle, ref vRect, 0);  // 只更新变动区域,防止闪烁,解决BitBlt光标滞留问题
                User.UpdateWindow(this.Handle);
            }
        }