コード例 #1
0
ファイル: Program.cs プロジェクト: fpgaq/FutureNNAimbot
        //Get screenshot on the center of game
        public static System.Drawing.Image CaptureWindow(string name, bool followMouse)
        {
            if (Process.GetProcessesByName(name).Count() == 0)
            {
                MessageBox.Show($"Looks like you closed {name}...");
                Process.GetCurrentProcess().Kill();
            }
            IntPtr handle = Process.GetProcessesByName(name)[0].MainWindowHandle;
            IntPtr hdcSrc = User32.GetWindowDC(handle);

            User32.RECT windowRect = new User32.RECT();
            User32.GetWindowRect(handle, ref windowRect);
            screen_width  = windowRect.right - windowRect.left;
            screen_height = windowRect.bottom - windowRect.top;
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, size.X, size.Y);
            IntPtr hOld    = GDI32.SelectObject(hdcDest, hBitmap);

            if (followMouse)
            {
                GDI32.BitBlt(hdcDest, 0, 0, size.X, size.Y, hdcSrc, coordinates.X - size.X / 2, coordinates.Y - size.Y / 2, GDI32.SRCCOPY);
            }
            else
            {
                GDI32.BitBlt(hdcDest, 0, 0, size.X, size.Y, hdcSrc, screen_width / 2 - size.X / 2, screen_height / 2 - size.Y / 2, GDI32.SRCCOPY);
            }
            GDI32.SelectObject(hdcDest, hOld);
            GDI32.DeleteDC(hdcDest);
            User32.ReleaseDC(handle, hdcSrc);
            System.Drawing.Image img = System.Drawing.Image.FromHbitmap(hBitmap);
            GDI32.DeleteObject(hBitmap);
            return(img);
        }
コード例 #2
0
        public void setHandle()
        {
            var p = Process.GetProcessesByName(game).FirstOrDefault();

            phnd = p?.MainWindowHandle ?? IntPtr.Zero;

            while (p == null)
            {
                Console.WriteLine("waiting for game");
                Console.ReadLine();
                p = Process.GetProcessesByName(game).FirstOrDefault();
                if (p == null)
                {
                    continue;
                }
                phnd = Process.GetProcessesByName(game).FirstOrDefault().MainWindowHandle;
            }

            ////set screencapture handles
            hdcSrc     = User32.GetWindowDC(phnd);
            windowRect = new User32.RECT();
            User32.GetWindowRect(phnd, ref windowRect);
            screen_width  = windowRect.right - windowRect.left;
            screen_height = windowRect.bottom - windowRect.top;
            hdcDest       = GDI32.CreateCompatibleDC(hdcSrc);
            hBitmap       = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
            hOld          = GDI32.SelectObject(hdcDest, hBitmap);
        }