示例#1
0
文件: Capture.cs 项目: zkdlu/Zoom
        private static Bitmap Screenshot(IntPtr hWnd)
        {
            try
            {
                IntPtr hDC = USER32.GetWindowDC(hWnd);

                RECT windowRect = new RECT();
                USER32.GetWindowRect(hWnd, ref windowRect);

                int width  = windowRect.right - windowRect.left;
                int height = windowRect.bottom - windowRect.top;

                IntPtr hdcDest = GDI32.CreateCompatibleDC(hDC);
                IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hDC, width, height);

                IntPtr hObj = GDI32.SelectObject(hdcDest, hBitmap);
                GDI32.BitBlt(hdcDest, 0, 0, width, height, hDC, 0, 0, USER32.SRCCOPY | USER32.CAPTUREBLT);
                GDI32.SelectObject(hdcDest, hObj);
                GDI32.DeleteDC(hdcDest);
                USER32.ReleaseDC(hWnd, hDC);

                Bitmap image = Image.FromHbitmap(hBitmap);
                GDI32.DeleteObject(hBitmap);

                return(image);
            }
            catch
            {
                return(new Bitmap(100, 100));
            }
        }
示例#2
0
文件: Capture.cs 项目: zkdlu/Zoom
        private static Bitmap Screenshot2(IntPtr hWnd)
        {
            try
            {
                Graphics  g    = Graphics.FromHwnd(hWnd);
                Rectangle rect = Rectangle.Round(g.VisibleClipBounds);

                if (rect.IsEmpty)
                {
                    return(Screenshot(hWnd));
                }

                Bitmap bitmap = new Bitmap(rect.Width, rect.Height, g);

                Graphics imgGraphics = Graphics.FromImage(bitmap);
                IntPtr   hdc         = imgGraphics.GetHdc();

                bool canCapture = USER32.PrintWindow(hWnd, hdc, 3);

                imgGraphics.ReleaseHdc(hdc);

                return(bitmap);
            }
            catch
            {
                return(new Bitmap(100, 100));
            }
        }
示例#3
0
        public static List <ProcessApi> GetRunnningProcesses()
        {
            var          list   = new List <ProcessApi>();
            EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
            {
                var result = new StringBuilder(255);
                USER32.GetWindowText(hWnd, result, result.Capacity + 1);
                string title = result.ToString();

                if (!string.IsNullOrEmpty(title) && USER32.IsWindowVisible(hWnd) && !title.Equals("Program Manager"))
                {
                    list.Add(new ProcessApi
                    {
                        Title  = title,
                        Handle = hWnd
                    });
                }

                return(true);
            };

            USER32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero);

            list = list.Where(r =>
            {
                int clocked;
                long result = DWMAPI.DwmGetWindowAttribute(r.Handle, DWMAPI.DWMWA_CLOAKED, out clocked, sizeof(int));
                if (result != 0L)
                {
                    clocked = 0;
                }

                return(clocked == 0);
            }).ToList();

            return(list);
        }
示例#4
0
文件: Capture.cs 项目: zkdlu/Zoom
        public static BitmapImage ScreenshotScreen()
        {
            IntPtr windowHandle = USER32.GetDesktopWindow();

            return(ConvertToBitmapImage(Screenshot(windowHandle)));
        }