Esempio n. 1
0
 public Monitor(UIElement element)
 {
     this.Element                = element;
     this.HwndSource             = ScreenLocation.FindTopLevelHwndSource(element);
     this.Element.LayoutUpdated += new EventHandler(this.OnLayoutUpdated);
     PresentationSource.AddSourceChangedHandler((IInputElement)element, new SourceChangedEventHandler(this.OnPresentationSourceChanged));
 }
Esempio n. 2
0
 private static IntPtr FindTopLevelWindow(IntPtr hWnd)
 {
     while (hWnd != IntPtr.Zero && ScreenLocation.IsChildWindow(hWnd))
     {
         hWnd = NativeMethods.GetParent(hWnd);
     }
     return(hWnd);
 }
Esempio n. 3
0
        public static HwndSource FindTopLevelHwndSource(UIElement element)
        {
            HwndSource hwndSource = (HwndSource)PresentationSource.FromVisual((Visual)element);

            if (hwndSource != null && ScreenLocation.IsChildWindow(hwndSource.Handle))
            {
                hwndSource = HwndSource.FromHwnd(ScreenLocation.FindTopLevelWindow(hwndSource.Handle));
            }
            return(hwndSource);
        }
Esempio n. 4
0
            private void TryUpdateLocation()
            {
                if (this.HwndSource == null || !this.Element.IsArrangeValid)
                {
                    return;
                }
                Point point = DpiHelper.DeviceToLogicalUnits(this.Element.PointToScreen(new Point(0.0, 0.0)));

                ScreenLocation.SetLeft(this.Element, point.X);
                ScreenLocation.SetTop(this.Element, point.Y);
                ScreenLocation.SetRight(this.Element, point.X + this.Element.RenderSize.Width);
                ScreenLocation.SetBottom(this.Element, point.Y + this.Element.RenderSize.Height);
            }
Esempio n. 5
0
 private void OnPresentationSourceChanged(object sender, SourceChangedEventArgs args)
 {
     this.HwndSource = ScreenLocation.FindTopLevelHwndSource((UIElement)sender);
     this.TryUpdateLocation();
 }