AdvancedLauncher.Tools.Interop.RedirectedWindow.UpdateRedirectedBitmap C# (CSharp) Method

UpdateRedirectedBitmap() public method

Returns a bitmap of the contents of the window.
RedirectedWindow maintains a bitmap internally and only allocates a new bitmap if the dimensions of the window have changed. Even if UpdateRedirectedBitmap returns the same bitmap, the contents are guaranteed to have been updated with the current contents of the window.
public UpdateRedirectedBitmap ( ) : System.Windows.Media.Imaging.BitmapSource
return System.Windows.Media.Imaging.BitmapSource
        public BitmapSource UpdateRedirectedBitmap()
        {
            RECT rcClient = new RECT();
            NativeMethods.GetClientRect(Handle, ref rcClient);
            if (_interopBitmap == null || rcClient.width != _bitmapWidth || rcClient.height != _bitmapHeight) {
                if (_interopBitmap != null) {
                    DestroyBitmap();
                }

                CreateBitmap(rcClient.width, rcClient.height);
            }

            // PrintWindow doesn't seem to work any better than BitBlt.
            // TODO: make it an option
            // User32.NativeMethods.PrintWindow(Handle, _hDC, PW.DEFAULT);

            IntPtr hdcSrc = NativeMethods.GetDC(Handle);
            NativeMethods.BitBlt(_hDC, 0, 0, _bitmapWidth, _bitmapHeight, hdcSrc, 0, 0, ROP.SRCCOPY);
            NativeMethods.ReleaseDC(Handle, hdcSrc);

            if (_interopBitmap != null) {
                _interopBitmap.Invalidate();
            }

            return _interopBitmap;
        }