public IntPtr Capture()
        {
            if (_hMemDc.Equals(IntPtr.Zero) || _hScrDc.Equals(IntPtr.Zero))
            {
                return(IntPtr.Zero);
            }

            var ret = Win32Funcs.PrintWindow(_hWnd, _hMemDc, (uint)Win32Consts.PrintWindowMode.PW_RENDERFULLCONTENT);

            return(ret ? _hBitmap : IntPtr.Zero);
        }
        public bool Init(string windowName)
        {
            var handle = Win32Funcs.FindWindow(null, windowName);

            if (handle.Equals(IntPtr.Zero))
            {
                return(false);
            }

            return(Init(handle));
        }
        public bool Capture(out IntPtr bitsPtr, out int bufferSize, out Win32Types.Rect rect)
        {
            bitsPtr    = _hBitmap;
            bufferSize = _bmpDataSize;
            rect       = _clientRect;

            if (_hBitmap.Equals(IntPtr.Zero) || _hMemDc.Equals(IntPtr.Zero) || _hScrDc.Equals(IntPtr.Zero))
            {
                return(false);
            }

            var ret = Win32Funcs.PrintWindow(_hWnd, _hMemDc, (uint)Win32Consts.PrintWindowMode.PW_RENDERFULLCONTENT);

            return(ret);
        }
        public void Cleanup()
        {
            if (_hBitmap.Equals(IntPtr.Zero))
            {
                return;
            }

            Win32Funcs.SelectObject(_hMemDc, _hOldBitmap);
            Win32Funcs.DeleteObject(_hBitmap);
            Win32Funcs.DeleteDC(_hMemDc);
            Win32Funcs.ReleaseDC(_hWnd, _hScrDc);

            _hWnd       = IntPtr.Zero;
            _hScrDc     = IntPtr.Zero;
            _hMemDc     = IntPtr.Zero;
            _hBitmap    = IntPtr.Zero;
            _hOldBitmap = IntPtr.Zero;
        }
        public bool Init(IntPtr handle)
        {
            _hWnd = handle;

            if (!Win32Funcs.GetWindowRect(_hWnd, out _windowRect) ||
                !Win32Funcs.GetClientRect(_hWnd, out _clientRect))
            {
                return(false);
            }

            _bmpDataSize = _windowRect.Width * _windowRect.Height * 3;

            _hScrDc     = Win32Funcs.GetWindowDC(_hWnd);
            _hBitmap    = Win32Funcs.CreateCompatibleBitmap(_hScrDc, _windowRect.Width, _windowRect.Height);
            _hMemDc     = Win32Funcs.CreateCompatibleDC(_hScrDc);
            _hOldBitmap = Win32Funcs.SelectObject(_hMemDc, _hBitmap);

            return(true);
        }