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;
}