Esempio n. 1
0
        public void UpdateWindowPos()
        {
            if (this._isDisposed)
            {
                return;
            }
            PresentationSource presentationSource = null;
            CompositionTarget  compositionTarget  = null;

            if (this.CriticalHandle != IntPtr.Zero && base.IsVisible)
            {
                presentationSource = PresentationSource.CriticalFromVisual(this, false);
                if (presentationSource != null)
                {
                    compositionTarget = presentationSource.CompositionTarget;
                }
            }
            if (compositionTarget != null && compositionTarget.RootVisual != null)
            {
                NativeMethods.RECT rc = this.CalculateAssignedRC(presentationSource);
                Rect rcBoundingBox    = PointUtil.ToRect(rc);
                this.OnWindowPositionChanged(rcBoundingBox);
                UnsafeNativeMethods.ShowWindowAsync(this._hwnd, 5);
                return;
            }
            UnsafeNativeMethods.ShowWindowAsync(this._hwnd, 0);
        }
Esempio n. 2
0
            internal Rect GetWindowRect()
            {
                NativeMethods.RECT rect = new NativeMethods.RECT(0, 0, 0, 0);

                if (IsWindowAlive())
                {
                    SafeNativeMethods.GetWindowRect(_window.CreateHandleRef(), ref rect);
                }

                return(PointUtil.ToRect(rect));
            }
Esempio n. 3
0
        /// <summary>
        ///     Updates the child window to reflect the state of this element.
        /// </summary>
        /// <remarks>
        ///     This includes the size of the window, the position of the
        ///     window, and the visibility of the window.
        /// </remarks>
        ///<remarks> Not available in Internet zone</remarks>
        public void UpdateWindowPos()
        {
            // Verify the thread has access to the context.
            // VerifyAccess();

            if (_isDisposed)
            {
                return;
            }

            // Position the child HWND where layout put it.  To do this we
            // have to get coordinates relative to the parent window.

            PresentationSource source = null;
            CompositionTarget  vt     = null;

            if ((CriticalHandle != IntPtr.Zero) && IsVisible)
            {
                source = PresentationSource.CriticalFromVisual(this, false /* enable2DTo3DTransition */);
                if (source != null)
                {
                    vt = source.CompositionTarget;
                }
            }

            if (vt != null && vt.RootVisual != null)
            {
                // Translate the layout information assigned to us from the co-ordinate
                // space of this element, through the root visual, to the Win32 client
                // co-ordinate space
                NativeMethods.RECT rcClientRTLAdjusted = CalculateAssignedRC(source);

                // Set the Win32 position for the child window.
                //
                // Note, we can't check the existing position because we use
                // SWP_ASYNCWINDOWPOS, which means we could have pending position
                // change requests that haven't been applied yet.  If we need
                // this functionality (to avoid the extra SetWindowPos calls),
                // we'll have to track the last RECT we sent Win32 ourselves.
                //
                Rect rectClientRTLAdjusted = PointUtil.ToRect(rcClientRTLAdjusted);
                OnWindowPositionChanged(rectClientRTLAdjusted);

                // Show the window
                // Based on Dwayne, the reason we also show/hide window in UpdateWindowPos is for the
                // following kind of scenario: When applying RenderTransform to HwndHost, the hwnd
                // will be left behind. Developer can workaround by hide the hwnd first using pinvoke.
                // After the RenderTransform is applied to the HwndHost, call UpdateWindowPos to sync up
                // the hwnd's location, size and visibility with WPF.
                UnsafeNativeMethods.ShowWindowAsync(_hwnd, NativeMethods.SW_SHOW);
            }
            else
            {
                // For some reason we shouldn't be displayed: either we don't
                // have a parent, or the parent no longer has a root visual,
                // or we are marked as not being visible.
                //
                // Just hide the window to get it out of the way.
                UnsafeNativeMethods.ShowWindowAsync(_hwnd, NativeMethods.SW_HIDE);
            }
        }