Esempio n. 1
0
        private double GetWindowBorderSize(CompilerWindow window)
        {
            // We need the WindowChrome data
            window.GetWindowChrome(out WindowChrome chrome);

            // We use the default
            if (window.WindowState != WindowState.Maximized)
            {
                return(chrome.ResizeBorderThickness.Left);
            }

            // Get the window handle
            IntPtr handle = (new WindowInteropHelper(window)).Handle;

            // Get the window styles
            uint style   = GetWindowLongA(handle, -16);
            uint exStyle = GetWindowLongA(handle, -20);

            // NOTE: Can be anything, I prefer to keep it safe (aka on-screen)
            const int WIN_WIDTH  = 640;
            const int WIN_HEIGHT = 480;

            // Fill with desired position (left/top) and size (right/bottom)
            RECT rect = new RECT()
            {
                left   = 0,
                right  = WIN_WIDTH,
                top    = 0,
                bottom = WIN_HEIGHT
            };

            // Make the call to WIN32
            if (AdjustWindowRectEx(ref rect, style, false, exStyle))
            {
                // Perform calculations to perform a check during debugging
                RECT dest = new RECT()
                {
                    left   = Math.Abs(rect.left),
                    top    = Math.Abs(rect.top),
                    right  = (rect.right - WIN_WIDTH),
                    bottom = (rect.bottom - WIN_HEIGHT)
                };
                Debug.Assert(dest.left == dest.right && dest.left == dest.bottom);

                return(Math.Abs(dest.left));
            }
            else
            {
                Debug.WriteLine(chrome.ResizeBorderThickness.Left);
                // Failsafe, use the exisiting border size
                return(chrome.ResizeBorderThickness.Left);
            }
        }
Esempio n. 2
0
        public object Convert(Grid grid)
        {
            object sender = Window.GetWindow(grid);

            Debug.Assert(sender != null);

            CompilerWindow window = sender as CompilerWindow;

            Debug.Assert(window != null);

            return(Convert(window, false));
        }
Esempio n. 3
0
        public object Convert(CompilerWindow window, bool adjustCaption)
        {
            // Get the border size
            double border = GetWindowBorderSize(window);

            if (adjustCaption)
            {
                // Adjust the caption height
                AdjustCaptionHeight(window, border);
            }

            // Return the size of the border
            return(new Thickness(border));
        }
Esempio n. 4
0
        private void AdjustCaptionHeight(CompilerWindow window, double border)
        {
            // We need the WindowChrome data
            window.GetWindowChrome(out WindowChrome chrome);

            // The original caption height
            double captionHeight = window.CaptionHeight;

            if (window.WindowState == WindowState.Maximized)
            {
                // Set the new caption height (extends beyond the visible screen!)
                chrome.CaptionHeight = (captionHeight + border - chrome.ResizeBorderThickness.Top);
            }
            else
            {
                chrome.CaptionHeight = captionHeight;
            }
        }