Esempio n. 1
0
        public static BitmapSource CaptureScreen(ReadOnlyRect rect)
        {
            var hdcSrc = GetAllMonitorsDC();

            var width   = rect.Width;
            var height  = rect.Height;
            var hdcDest = CreateCompatibleDC(hdcSrc);
            var hBitmap = CreateCompatibleBitmap(hdcSrc, width, height);

            _ = SelectObject(hdcDest, hBitmap);

            BitBlt(hdcDest, 0, 0, width, height, hdcSrc, rect.X, rect.Y,
                   TernaryRasterOperations.SRCCOPY | TernaryRasterOperations.CAPTUREBLT);

            var image  = Image.FromHbitmap(hBitmap);
            var bitmap = image.ToBitmapSource();

            //bitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty,
            //    BitmapSizeOptions.FromEmptyOptions());

            DeleteObject(hBitmap);
            DeleteDC(hdcDest);
            DeleteDC(hdcSrc);

            return(bitmap);
        }
Esempio n. 2
0
 private static IReadOnlyList <CachedRect> CriticalGetChildren(
     AutomationElement parentElement,
     ReadOnlyRect physicalParentRect)
 {
     return(parentElement.FindAll(TreeScope.Children, ChildrenCondition)
            .OfType <AutomationElement>()
            .Select(item => (element: item, rect: GetRect(item, physicalParentRect)))
            .Where(item => item.rect != ReadOnlyRect.Empty)
            .Select(item => new CachedRect(item.element, item.rect))
            .ToList());
 }
Esempio n. 3
0
 private static void SetWindowRect(Window window, ReadOnlyRect rect)
 {
     SetWindowPos(
         window.GetHandle(),
         (IntPtr)HWND_TOPMOST,
         rect.X,
         rect.Y,
         rect.Width,
         rect.Height,
         SWP_NOZORDER);
 }
Esempio n. 4
0
 private static ReadOnlyRect GetRect(AutomationElement element, ReadOnlyRect physicalParentRect)
 {
     try
     {
         ReadOnlyRect rect = element.Current.BoundingRectangle;
         return(rect == ReadOnlyRect.Empty ? ReadOnlyRect.Empty : rect.Intersect(physicalParentRect));
     }
     catch
     {
         return(ReadOnlyRect.Empty);
     }
 }
Esempio n. 5
0
        public MonitorInfo(IntPtr handle, bool isPrimaryScreen, ReadOnlyRect workArea, ReadOnlyRect screenRect)
        {
            Handle             = handle;
            IsPrimaryScreen    = isPrimaryScreen;
            PhysicalWorkArea   = workArea;
            PhysicalScreenRect = screenRect;
            (ScaleX, ScaleY)   = MonitorHelper.GetScaleFactorFromMonitor(handle);

            var(x, y, width, height) = ToWpfAxis(
                screenRect.X,
                screenRect.Y,
                screenRect.Width,
                screenRect.Height);
            WpfAxisScreenRect = new Rect(x, y, width, height);
        }
Esempio n. 6
0
        private static IReadOnlyList <CachedRect> GetChildren(AutomationElement parentElement,
                                                              ReadOnlyRect physicalParentRect)
        {
            try
            {
                return(CriticalGetChildren(parentElement, physicalParentRect));
            }
            catch
            {
                // Ignore Exception

                // * System.Runtime.InteropServices.COMException:
                // 'An outgoing call cannot be made since the application is dispatching an input-synchronous call.
                // (Exception from HRESULT: 0x8001010D (RPC_E_CANT CALL OUT_IN INPUT SYNC CALL))'
                // * System.ArgumentException:
                // 'Value does not fall within the expected range.'
                // * System.Windows.Automation.ElementNotAvailableException:
                // 'The target element corresponds to UI that is no longer available (for example, the parent window has closed).'
                // * System.Runtime.InteropServices.COMException:
                // 'Error HRESULT E_FAIL has been returned from a call to a COM component.'

                return(EmptyChildren);
            }
        }
Esempio n. 7
0
 public void Snapshot(ReadOnlyRect physicalFullScreenRect)
 {
     _elementSnapshot = GetChildren(AutomationElement.RootElement, physicalFullScreenRect);
 }
Esempio n. 8
0
 public CachedRect(AutomationElement element, ReadOnlyRect physicalRect)
 {
     Element      = element;
     PhysicalRect = physicalRect;
 }