示例#1
0
        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);
        }
示例#2
0
        public bool Init(string windowName)
        {
            var handle = Win32Funcs.FindWindow(null, windowName);

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

            return(Init(handle));
        }
示例#3
0
        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);
        }
示例#4
0
        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;
        }
示例#5
0
        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);
        }