Exemplo n.º 1
0
        internal Window(IntPtr hWnd, string className, string displayName, string processName, int workspacesCount, bool is64BitProcess,
                        NativeMethods.WS originalStyle, NativeMethods.WS_EX originalExStyle, ProgramRule.Rule rule, ProgramRule programRule, IntPtr menu) :
            base(hWnd)
        {
            IsFloating                = rule.isFloating;
            Titlebar                  = rule.titlebar;
            InAltTabAndTaskbar        = rule.inAltTabAndTaskbar;
            WindowBorders             = rule.windowBorders;
            this.WorkspacesCount      = workspacesCount;
            this.DisplayName          = displayName;
            this.className            = className;
            this.processName          = processName;
            this.is64BitProcess       = is64BitProcess;
            redrawOnShow              = rule.redrawOnShow;
            ShowMenu                  = programRule.showMenu;
            updateIcon                = programRule.updateIcon;
            onHiddenWindowShownAction = programRule.onHiddenWindowShownAction;
            this.menu                 = menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = rule.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle   = originalStyle;
            this.originalExStyle = originalExStyle;

            windowPlacement = NativeMethods.WINDOWPLACEMENT.Default;
            SavePosition();
            originalWindowPlacement = windowPlacement;

            this.customOwnedWindowMatchingFunction = programRule.customOwnedWindowMatchingFunction;

            this.ownedWindows = new LinkedList <IntPtr>();
            this.ownedWindows.AddFirst(hWnd);
        }
Exemplo n.º 2
0
        internal Window(Window window) : base(window)
        {
            this.IsFloating         = window.IsFloating;
            this.Titlebar           = window.Titlebar;
            this.InAltTabAndTaskbar = window.InAltTabAndTaskbar;
            this.WindowBorders      = window.WindowBorders;
            this.WorkspacesCount    = window.WorkspacesCount;
            this.DisplayName        = window.DisplayName;
            className                 = window.className;
            processName               = window.processName;
            is64BitProcess            = window.is64BitProcess;
            redrawOnShow              = window.redrawOnShow;
            ShowMenu                  = window.ShowMenu;
            updateIcon                = window.updateIcon;
            onHiddenWindowShownAction = window.onHiddenWindowShownAction;
            menu = window.menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = window.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle   = window.originalStyle;
            this.originalExStyle = window.originalExStyle;

            windowPlacement         = window.windowPlacement;
            originalWindowPlacement = window.originalWindowPlacement;

            this.customOwnedWindowMatchingFunction = window.customOwnedWindowMatchingFunction;
            ownedWindows = window.ownedWindows;
        }
Exemplo n.º 3
0
        private IntPtr OnNCCalcSize(IntPtr hwnd, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            NativeMethods.WINDOWPLACEMENT placement = NativeMethods.GetWindowPlacement(hwnd);

            // Need to handle the maxmized case to remove the caption area or else when the window
            // is maximized the default chrome will come back
            if (placement.showCmd == NativeMethods.SW_SHOWMAXIMIZED)
            {
                NativeMethods.DefWindowProc(hwnd, NativeMethods.WM_NCCALCSIZE, wParam, lParam);

                NativeMethods.RECT screenRect = (NativeMethods.RECT)Marshal.PtrToStructure(lParam, typeof(NativeMethods.RECT));

                // Here is where we remove the caption height to hide the default window chrome
                //
                // SystemParameters.CaptionHeight is in logical units and needs to be converted to
                // device units in order to work for all cases. As written, this only works for
                // displays that are set at 100% scale factor.
                screenRect.top -= (int)Math.Ceiling(SystemParameters.CaptionHeight + 1);

                // TODO: Should handle when the task bar is auto-hidden, but that's left as an
                // exercise to the reader.

                Marshal.StructureToPtr(screenRect, lParam, fDeleteOld: true);
            }

            // In the non-maximized case, keep the default size, which will fill the window's
            // entire rect with client area, allowing us to draw custom chrome. In both cases,
            // don't call DefWindowProc, which would overwrite these values.
            handled = true;
            return(IntPtr.Zero);
        }
Exemplo n.º 4
0
        internal Window(IntPtr hWnd, string className, string displayName, string processName, int workspacesCount, bool is64BitProcess,
            NativeMethods.WS originalStyle, NativeMethods.WS_EX originalExStyle, ProgramRule.Rule rule, ProgramRule programRule, IntPtr menu)
            : base(hWnd)
        {
            IsFloating = rule.isFloating;
            Titlebar = rule.titlebar;
            InAltTabAndTaskbar = rule.inAltTabAndTaskbar;
            WindowBorders = rule.windowBorders;
            this.WorkspacesCount = workspacesCount;
            this.DisplayName = displayName;
            this.className = className;
            this.processName = processName;
            this.is64BitProcess = is64BitProcess;
            redrawOnShow = rule.redrawOnShow;
            ShowMenu = programRule.showMenu;
            updateIcon = programRule.updateIcon;
            onHiddenWindowShownAction = programRule.onHiddenWindowShownAction;
            this.menu = menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = rule.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle = originalStyle;
            this.originalExStyle = originalExStyle;

            windowPlacement = NativeMethods.WINDOWPLACEMENT.Default;
            SavePosition();
            originalWindowPlacement = windowPlacement;

            this.customOwnedWindowMatchingFunction = programRule.customOwnedWindowMatchingFunction;

            this.ownedWindows = new LinkedList<IntPtr>();
            this.ownedWindows.AddFirst(hWnd);
        }
Exemplo n.º 5
0
        internal Window(Window window)
            : base(window)
        {
            this.IsFloating = window.IsFloating;
            this.Titlebar = window.Titlebar;
            this.InAltTabAndTaskbar = window.InAltTabAndTaskbar;
            this.WindowBorders = window.WindowBorders;
            this.WorkspacesCount = window.WorkspacesCount;
            this.DisplayName = window.DisplayName;
            className = window.className;
            processName = window.processName;
            is64BitProcess = window.is64BitProcess;
            redrawOnShow = window.redrawOnShow;
            ShowMenu = window.ShowMenu;
            updateIcon = window.updateIcon;
            onHiddenWindowShownAction = window.onHiddenWindowShownAction;
            menu = window.menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = window.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle = window.originalStyle;
            this.originalExStyle = window.originalExStyle;

            windowPlacement = window.windowPlacement;
            originalWindowPlacement = window.originalWindowPlacement;

            this.customOwnedWindowMatchingFunction = window.customOwnedWindowMatchingFunction;
            ownedWindows = window.ownedWindows;
        }
Exemplo n.º 6
0
        private static void SetWindowPlacement(IntPtr hWnd, int cmdShow)
        {
            NativeMethods.WINDOWPLACEMENT windowPlacement = new NativeMethods.WINDOWPLACEMENT();
            NativeMethods.GetWindowPlacement(hWnd, out windowPlacement);
            windowPlacement.showCmd = cmdShow;

            NativeMethods.SetWindowPlacement(hWnd, windowPlacement);
        }
Exemplo n.º 7
0
        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            ISite site = ParentInternal?.Site;

            if (IsHandleCreated && (site == null || !site.DesignMode))
            {
                Rectangle oldBounds = Bounds;
                base.SetBoundsCore(x, y, width, height, specified);
                Rectangle newBounds = Bounds;

                int yDelta = oldBounds.Height - newBounds.Height;
                if (yDelta != 0)
                {
                    // NOTE: This logic is to keep minimized MDI children anchored to
                    // the bottom left of the client area, normally they are anchored
                    // to the top right which just looks wierd!
                    //
                    NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT
                    {
                        length = Marshal.SizeOf <NativeMethods.WINDOWPLACEMENT>()
                    };

                    for (int i = 0; i < Controls.Count; i++)
                    {
                        Control ctl = Controls[i];
                        if (ctl != null && ctl is Form)
                        {
                            Form child = (Form)ctl;
                            // Only adjust the window position for visible MDI Child windows to prevent
                            // them from being re-displayed.
                            if (child.CanRecreateHandle() && child.WindowState == FormWindowState.Minimized)
                            {
                                UnsafeNativeMethods.GetWindowPlacement(new HandleRef(child, child.Handle), ref wp);
                                wp.ptMinPosition.Y -= yDelta;
                                if (wp.ptMinPosition.Y == -1)
                                {
                                    if (yDelta < 0)
                                    {
                                        wp.ptMinPosition.Y = 0;
                                    }
                                    else
                                    {
                                        wp.ptMinPosition.Y = -2;
                                    }
                                }
                                wp.flags = NativeMethods.WPF_SETMINPOSITION;
                                UnsafeNativeMethods.SetWindowPlacement(new HandleRef(child, child.Handle), ref wp);
                                wp.flags = 0;
                            }
                        }
                    }
                }
            }
            else
            {
                base.SetBoundsCore(x, y, width, height, specified);
            }
        }
Exemplo n.º 8
0
        public static SW GetWindowState(IntPtr handle)
        {
            NativeMethods.WINDOWPLACEMENT placement = new NativeMethods.WINDOWPLACEMENT();
            placement.Length = Marshal.SizeOf(placement);
            NativeMethods.GetWindowPlacement(handle, ref placement);

            SW state = (SW)placement.ShowCmd;

            return(state);
        }
Exemplo n.º 9
0
        /// <include file='doc\MDIClient.uex' path='docs/doc[@for="MdiClient.SetBoundsCore"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            ISite site = (ParentInternal == null) ? null : ParentInternal.Site;

            if (IsHandleCreated && (site == null || !site.DesignMode))
            {
                Rectangle oldBounds = Bounds;
                base.SetBoundsCore(x, y, width, height, specified);
                Rectangle newBounds = Bounds;

                int yDelta = oldBounds.Height - newBounds.Height;

                // NOTE: This logic is to keep minimized MDI children anchored to
                // the bottom left of the client area, normally they are anchored
                // to the top right which just looks wierd!
                //
                NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
                wp.length = Marshal.SizeOf(typeof(NativeMethods.WINDOWPLACEMENT));

                for (int i = 0; i < Controls.Count; i++)
                {
                    Control ctl = Controls[i];
                    if (ctl != null && ctl is Form)
                    {
                        Form child = (Form)ctl;
                        if (child.WindowState == FormWindowState.Minimized)
                        {
                            UnsafeNativeMethods.GetWindowPlacement(new HandleRef(child, child.Handle), ref wp);
                            wp.ptMinPosition_y -= yDelta;
                            if (wp.ptMinPosition_y == -1)
                            {
                                if (yDelta < 0)
                                {
                                    wp.ptMinPosition_y = 0;
                                }
                                else
                                {
                                    wp.ptMinPosition_y = -2;
                                }
                            }
                            wp.flags = NativeMethods.WPF_SETMINPOSITION;
                            UnsafeNativeMethods.SetWindowPlacement(new HandleRef(child, child.Handle), ref wp);
                            wp.flags = 0;
                        }
                    }
                }
            }
            else
            {
                base.SetBoundsCore(x, y, width, height, specified);
            }
        }
Exemplo n.º 10
0
        private static void SaveWINDOWPLACEMENT(NativeMethods.WINDOWPLACEMENT value, IObjectData data, bool omitDefault)
        {
            // argument checks
            Debug.Assert(data != null);

            // save WINDOWPLACEMENT value
            // there values are not omitted
            data.SetInt32Value(SettingNames.Flags, value.Flags);
            data.SetInt32Value(SettingNames.ShowCmd, value.ShowCmd);
            data.SetObjectValue(SettingNames.MinPosition, value.MinPosition, SavePOINT);
            data.SetObjectValue(SettingNames.MaxPosition, value.MaxPosition, SavePOINT);
            data.SetObjectValue(SettingNames.NormalPosition, value.NormalPosition, SaveRECT);

            return;
        }
Exemplo n.º 11
0
        private static NativeMethods.WINDOWPLACEMENT CreateWINDOWPLACEMENT(IObjectData data)
        {
            // argument checks
            Debug.Assert(data != null);

            // create WINDOWPLACEMENT value
            NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
            wp.Flags          = data.GetInt32Value(SettingNames.Flags, Defaults.Flags);
            wp.ShowCmd        = data.GetInt32Value(SettingNames.ShowCmd, Defaults.ShowCmd);
            wp.MinPosition    = data.GetObjectValue(SettingNames.MinPosition, Defaults.Point, CreatePOINT);
            wp.MaxPosition    = data.GetObjectValue(SettingNames.MaxPosition, Defaults.Point, CreatePOINT);
            wp.NormalPosition = data.GetObjectValue(SettingNames.NormalPosition, Defaults.Rect, CreateRECT);

            return(wp);
        }
Exemplo n.º 12
0
 private bool SetWindowPlacement(NativeMethods.WINDOWPLACEMENT windowPlacement)
 {
     if (_form == null)
     {
         throw (new NullReferenceException("WindowPlacement.Form is not set."));
     }
     windowPlacement.length = (uint)Marshal.SizeOf(windowPlacement);
     try
     {
         return(NativeMethods.SetWindowPlacement(_form.Handle, ref windowPlacement));
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 13
0
        internal void RevertToInitialValues()
        {
            this.Titlebar           = State.SHOWN;
            this.InAltTabAndTaskbar = State.SHOWN;
            this.WindowBorders      = State.SHOWN;
            Initialize();

            if (!ShowMenu)
            {
                ToggleShowHideWindowMenu();
            }

            windowPlacement = originalWindowPlacement;
            RestorePosition(false);
            ShowAsync();
        }
Exemplo n.º 14
0
        public static WindowState GetHwndState(IntPtr hWnd)
        {
            SecurityHelper.DemandUnmanagedCode();
            SecurityHelper.DemandUIWindowPermission();

            var placement = new NativeMethods.WINDOWPLACEMENT();

            ThrowLastError(!SafeNativeMethods.GetWindowPlacement(hWnd, ref placement));
            switch (placement.showCmd)
            {
            case NativeMethods.WindowState.SW_SHOWMINIMIZED: return(WindowState.Minimized);

            case NativeMethods.WindowState.SW_SHOWMAXIMIZED: return(WindowState.Maximized);
            }
            return(WindowState.Normal);
        }
Exemplo n.º 15
0
        bool OnParentWmWindowPosChanged(ref Message m, BaseWndProc baseProc)
        {
            if (this.ParentForm == null || this.ParentForm.IsHandleCreated == false)
            {
                return(false);
            }

            // recover the correct size of the parent window
            // after the Form's WM_WINDOWPOSCHANGED handler messes it up.

            // 1a. minimise             FormWindowState.Normal, SW_SHOWMINIMIZED
            // 1b. maximise             FormWindowState.Maximized, SW_SHOWMAXIMIZED
            // 2. restore (ignore)      FormWindowState.Minimized, SW_SHOWMINIMIZED
            // 3. reentrant (<<here)    FormWindowState.Normal, SW_SHOWNORMAL

            var parentForm = this.ParentForm;
            var wp         = new NativeMethods.WINDOWPLACEMENT();

            wp.length = Marshal.SizeOf(typeof(NativeMethods.WINDOWPLACEMENT));
            UnsafeNativeMethods.GetWindowPlacement(this.ParentForm.Handle, ref wp);

            var saveSize = (wp.showCmd == NativeMethods.SW_SHOWMINIMIZED) ||
                           (wp.showCmd == NativeMethods.SW_SHOWMAXIMIZED);

            if (saveSize)
            {
                this.restoredWindowSize = wp.rcNormalPosition.ToRectangle().Size;
                this.restoredSizeSaved  = true;
            }

            var stage2 = parentForm.WindowState == FormWindowState.Minimized && wp.showCmd == NativeMethods.SW_SHOWMINIMIZED;
            var stage3 = parentForm.WindowState == FormWindowState.Normal && wp.showCmd == NativeMethods.SW_SHOWNORMAL;

            baseProc(ref m);

            if (this.restoredSizeSaved && stage3)
            {
                this.restoredSizeSaved = false;
                //parentForm.Refresh();
                parentForm.Size = this.restoredWindowSize;
            }
            else if (stage2)
            {
            }
            return(true);
        }
Exemplo n.º 16
0
 private NativeMethods.WINDOWPLACEMENT GetWindowPlacement()
 {
     if (_form == null)
     {
         throw (new NullReferenceException("WindowPlacement.Form is not set."));
     }
     NativeMethods.WINDOWPLACEMENT windowPlacement = new NativeMethods.WINDOWPLACEMENT();
     windowPlacement.length = (uint)Marshal.SizeOf(windowPlacement);
     try
     {
         NativeMethods.GetWindowPlacement(_form.Handle, ref windowPlacement);
         return windowPlacement;
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 17
0
		/// <summary>
		/// Gets the window style.
		/// </summary>
		/// <returns>The style currently applied to the ie window.</returns>
		public NativeMethods.WindowShowStyle GetWindowStyle()
		{
			NativeMethods.WINDOWPLACEMENT placement = new NativeMethods.WINDOWPLACEMENT();
			placement.length = Marshal.SizeOf(placement);

			NativeMethods.GetWindowPlacement(hWnd, ref placement);

			return (NativeMethods.WindowShowStyle) placement.showCmd;
		}
Exemplo n.º 18
0
        private void UpdateHwndRestoreBounds(double newValue, BoundsSpecified specifiedRestoreBounds)
        {
            SecurityHelper.DemandUIWindowPermission();

            NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
            wp.length = Marshal.SizeOf(typeof(NativeMethods.WINDOWPLACEMENT));
            UnsafeNativeMethods.GetWindowPlacement(new HandleRef(this, CriticalHandle), ref wp);

            double convertedValue = (LogicalToDeviceUnits(new Point(newValue, 0))).X;
            switch (specifiedRestoreBounds)
            {
                case BoundsSpecified.Height:
                    wp.rcNormalPosition_bottom = wp.rcNormalPosition_top + DoubleUtil.DoubleToInt(convertedValue);
                    break;
                case BoundsSpecified.Width:
                    wp.rcNormalPosition_right = wp.rcNormalPosition_left + DoubleUtil.DoubleToInt(convertedValue);
                    break;
                case BoundsSpecified.Top:
                    // convert input value into work-area co-ods
                    double newTop = newValue;
                    // [Get/Set]WindowPlacement work with workarea co-ods for a top level
                    // window whose WS_EX_TOOLWINDOW bit is clear.  If this bit is set,
                    // then the co-ods are expected to be in screen co-ods of the monitor.
                    // TransfromWorkAreaScreenArea can transform a point from work area co-ods
                    // to screen area co-ods and vice versa depending on TransformType value passed.
                    // So, in our case, if the window is not a ToolWindow we want to transform
                    // the input value from screen co-ods to work area co-ods.
                    if ((StyleExFromHwnd & NativeMethods.WS_EX_TOOLWINDOW) == 0)
                    {
                        newTop = TransformWorkAreaScreenArea(new Point(0, newTop), TransformType.ScreenAreaToWorkArea).Y;
                    }
                    newTop = (LogicalToDeviceUnits(new Point(0, newTop))).Y;
                    int currentHeight = wp.rcNormalPosition_bottom - wp.rcNormalPosition_top;
                    wp.rcNormalPosition_top = DoubleUtil.DoubleToInt(newTop);
                    wp.rcNormalPosition_bottom = wp.rcNormalPosition_top + currentHeight;
                    break;
                case BoundsSpecified.Left:
                    // convert input value into work-area co-ods
                    double newLeft = newValue;
                    // [Get/Set]WindowPlacement work with workarea co-ods for a top level
                    // window whose WS_EX_TOOLWINDOW bit is clear.  If this bit is set,
                    // then the co-ods are expected to be in screen co-ods of the monitor.
                    // TransfromWorkAreaScreenArea can transform a point from work area co-ods
                    // to screen area co-ods and vice versa depending on TransformType value passed.

                    // So, in our case, if the window is not a ToolWindow we want to transform
                    // the input value from screen co-ods to work area co-ods.
                    if ((StyleExFromHwnd & NativeMethods.WS_EX_TOOLWINDOW) == 0)
                    {
                        newLeft = TransformWorkAreaScreenArea(new Point(newLeft, 0), TransformType.ScreenAreaToWorkArea).X;
                    }
                    newLeft = (LogicalToDeviceUnits(new Point(newLeft, 0))).X;
                    int currentWidth = wp.rcNormalPosition_right - wp.rcNormalPosition_left;
                    wp.rcNormalPosition_left = DoubleUtil.DoubleToInt(newLeft);
                    wp.rcNormalPosition_right = wp.rcNormalPosition_left + currentWidth;
                    break;
                default:
                    Debug.Assert(false, String.Format("specifiedRestoreBounds can't be {0}", specifiedRestoreBounds));
                    break;
            }

            // The showCmd flag retreived by GetWindowPlacement is SW_SHOWMAXIMIZED when the window is maximized.
            // If the window is minimized, showCmd is SW_SHOWMINIMIZED. Otherwise, it is SW_SHOWNORMAL, regardless
            // of the window's visibility.
            // SetWindowPlacement with SW_SHOWMAXIMIZED and SW_SHOWMINIMIZED will cause a hidden window to show.
            // To workaround this issue, we check whether the current window is hidden and set showCmd to SW_HIDE if it is.
            if (!this._isVisible)
            {
                wp.showCmd = NativeMethods.SW_HIDE;
            }


            UnsafeNativeMethods.SetWindowPlacement(new HandleRef(this, CriticalHandle), ref wp);
        }
Exemplo n.º 19
0
        private void OnWindowStateChanged(WindowState windowState)
        {
            SecurityHelper.DemandUIWindowPermission();

            // 











            if (IsSourceWindowNull == false && IsCompositionTargetInvalid == false)
            {
                if (_isVisible == true)
                {
                    HandleRef hr = new HandleRef(this,  CriticalHandle);

                    int style = _Style;

                    // Only call ShowWindow if window is in a different state
                    switch (windowState)
                    {
                        case WindowState.Normal:
                            if ((style & NativeMethods.WS_MAXIMIZE) == NativeMethods.WS_MAXIMIZE)
                            {
                                //
                                // The old behavior of this case is to restore the window using SW_RESTORE.
                                // With the ShowActivated property set to false we want this restore operation
                                // to take the current activation state into account when restoring the window.
                                //
                                if (ShowActivated || IsActive)
                                    UnsafeNativeMethods.ShowWindow(hr, NativeMethods.SW_RESTORE);
                                else
                                    UnsafeNativeMethods.ShowWindow(hr, NativeMethods.SW_SHOWNOACTIVATE);
                            }
                            else if ((style & NativeMethods.WS_MINIMIZE) == NativeMethods.WS_MINIMIZE)
                            {
                                //
                                // We query to WINDOWPLACEMENT to get an indication about the state before the
                                // minimize operation happened. If we were coming from a maximized state and now we
                                // switch to normal, we want activation to happen since the maximized state is always
                                // activated and transitioning from activated to non-activated would be weird.
                                //
                                NativeMethods.WINDOWPLACEMENT placement = new NativeMethods.WINDOWPLACEMENT();
                                placement.length = Marshal.SizeOf(placement);
                                UnsafeNativeMethods.GetWindowPlacement(hr, ref placement);

                                if ((placement.flags & NativeMethods.WPF_RESTORETOMAXIMIZED) == NativeMethods.WPF_RESTORETOMAXIMIZED)
                                    UnsafeNativeMethods.ShowWindow(hr, NativeMethods.SW_RESTORE);
                                else
                                {
                                    if (ShowActivated)
                                        UnsafeNativeMethods.ShowWindow(hr, NativeMethods.SW_RESTORE);
                                    else
                                        UnsafeNativeMethods.ShowWindow(hr, NativeMethods.SW_SHOWNOACTIVATE);
                                }
                            }
                            break;

                        case WindowState.Maximized:
                            if ((style & NativeMethods.WS_MAXIMIZE) != NativeMethods.WS_MAXIMIZE)
                            {
                                //
                                // The OS doesn't provide support for non-activated maximized windows.
                                //
                                UnsafeNativeMethods.ShowWindow(hr, NativeMethods.SW_MAXIMIZE);
                            }
                            break;

                        case WindowState.Minimized:
                            if ((style & NativeMethods.WS_MINIMIZE) != NativeMethods.WS_MINIMIZE)
                            {
                                //
                                // Historically, we used SW_MINIMIZE in here which activates the next top-level
                                // window in the Z order. Therefore, our ShowActivated property can't affect the
                                // minimized state since this would incur a breaking change requiring us to use
                                // SW_SHOWMINIMIZED instead in case ShowActivated is set to true (bw compat case).
                                //
                                UnsafeNativeMethods.ShowWindow(hr, NativeMethods.SW_MINIMIZE);
                            }
                            break;
                        // 



                    }
                }
            }
            else
            {
                // WindowState can be changed as a result of the following two passes
                // 1. User interaction changes WindowState
                // 2. Developer programmatically changes WindowState
                // We update _previousWindowState at two places
                // 1. Before Hwnd is created, when developer programmatically changes WindowState, we update it here.
                // 2. After Hwnd is created, we update it when we get to WM_SIZE because both passes eventally meet there.
                _previousWindowState = windowState;
            }

            // The value of Top and Left is affected by WindowState and WindowStartupLocation.
            // we need to coerce Top and Left whenever these deciding factors change.
            // More info in CoerceTop.
            try
            {
                _updateHwndLocation = false;
                CoerceValue(TopProperty);
                CoerceValue(LeftProperty);
            }
            finally
            {
                _updateHwndLocation = true;
            }
        }
Exemplo n.º 20
0
        private Rect GetNormalRectDeviceUnits(IntPtr hwndHandle)
        {
            int styleEx = UnsafeNativeMethods.GetWindowLong(new HandleRef(this, hwndHandle), NativeMethods.GWL_EXSTYLE);

            NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
            wp.length = Marshal.SizeOf(typeof(NativeMethods.WINDOWPLACEMENT));
            UnsafeNativeMethods.GetWindowPlacement(new HandleRef(this, hwndHandle), ref wp);
            Point locationDeviceUnits = new Point(wp.rcNormalPosition_left, wp.rcNormalPosition_top);

            // GetWindowPlacement returns workarea co-ods for a top level window whose
            // WS_EX_TOOLWINDOW bit is clear.  If this bit is set, then the co-ods
            // returned are relative to the screen co-ods of the monitor.
            // TransfromWorkAreaScreenArea can transform a point from work area co-ods
            // to screen area co-ods and vice versa depending on TransformType value passed.
            // So, in our case, if the window is not a ToolWindow we want to transform
            // the point from work area co-ods to screen co-ods.
            if ((styleEx & NativeMethods.WS_EX_TOOLWINDOW) == 0)
            {
                locationDeviceUnits = TransformWorkAreaScreenArea(locationDeviceUnits, TransformType.WorkAreaToScreenArea);
            }

            Point sizeDeviceUnits = new Point(wp.rcNormalPosition_right - wp.rcNormalPosition_left,
                                              wp.rcNormalPosition_bottom - wp.rcNormalPosition_top);

            return new Rect(locationDeviceUnits.X, locationDeviceUnits.Y, sizeDeviceUnits.X, sizeDeviceUnits.Y);
        }
Exemplo n.º 21
0
 internal static extern int GetWindowPlacement(IntPtr hwnd, ref NativeMethods.WINDOWPLACEMENT lpwndpl);
Exemplo n.º 22
0
        internal void RevertToInitialValues()
        {
            this.Titlebar = State.SHOWN;
            this.InAltTabAndTaskbar = State.SHOWN;
            this.WindowBorders = State.SHOWN;
            Initialize();

            if (!ShowMenu)
            {
                ToggleShowHideWindowMenu();
            }

            windowPlacement = originalWindowPlacement;
            RestorePosition(false);
            ShowAsync();
        }
Exemplo n.º 23
0
        public static SW GetWindowState(IntPtr handle)
        {
            NativeMethods.WINDOWPLACEMENT placement = new NativeMethods.WINDOWPLACEMENT();
            placement.Length = Marshal.SizeOf(placement);
            NativeMethods.GetWindowPlacement(handle, ref placement);

            SW state = (SW)placement.ShowCmd;
            return state;
        }
Exemplo n.º 24
0
 /// <summary>
 /// Returns whether a window is normal (1), minimized (2), or maximized (3).
 /// </summary>
 /// <param name="hWnd">The handle of the window.</param>
 private NativeMethods.WindowShowStyle GetWindowShowStyle(IntPtr hWnd)
 {
     NativeMethods.WINDOWPLACEMENT placement = new NativeMethods.WINDOWPLACEMENT();
     NativeMethods.GetWindowPlacement(hWnd, ref placement);
     return(placement.showCmd);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Attach to client's message loop, restore window if minimized, and bring window forward.
 /// </summary>
 public bool PrepareWindowForInput()
 {
     NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
     uint thread = NativeMethods.GetCurrentThreadId();
     if (NativeMethods.AttachThreadInput(thread, this.ThreadID, true))
     {
         if (NativeMethods.GetWindowPlacement(this.WindowHandle, ref wp))
         {
             if (wp.showCmd == NativeMethods.SW_SHOWMINIMIZED)
             {
                 wp.showCmd = NativeMethods.SW_SHOWDEFAULT;
                 if (!NativeMethods.SetWindowPlacement(this.WindowHandle, ref wp))
                     return false;
             }
             return NativeMethods.SetForegroundWindow(this.WindowHandle);
         }
     }
     return false;
 }
Exemplo n.º 26
0
 public static bool IsWindowMaximized(IntPtr handle)
 {
     NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
     NativeMethods.GetWindowPlacement(handle, ref wp);
     return wp.showCmd == (int)NativeMethods.SHOWWINDOW.SW_MAXIMIZE;
 }
Exemplo n.º 27
0
 public static extern bool GetWindowPlacement(IntPtr hwnd, ref NativeMethods.WINDOWPLACEMENT lpwndpl);
Exemplo n.º 28
0
 /// <summary>
 /// Returns whether a window is normal (1), minimized (2), or maximized (3).
 /// </summary>
 /// <param name="hWnd">The handle of the window.</param>
 public int GetWindowPlacement(IntPtr hWnd)
 {
     NativeMethods.WINDOWPLACEMENT placement = new NativeMethods.WINDOWPLACEMENT();
     NativeMethods.GetWindowPlacement(hWnd, ref placement);
     return(placement.showCmd);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Send mouse click to relative position in the client window.
        /// </summary>
        /// <param name="client">Target client.</param>
        /// <param name="button">System.Windows.Forms.MouseButtons to click.</param>
        /// <param name="x">X position of point to click relative to client window's X position.</param>
        /// <param name="y">Y position of point to click relative to client window's Y position.</param>
        /// <param name="doubleClick">True for double click, false for single click.</param>
        /// <returns>True on success.</returns>
        public static bool SendMouseClick(int client, MouseButtons button, int x, int y, bool doubleClick)
        {
            ClientInfo ci;

            if (ClientInfoCollection.GetClient(client, out ci))
            {
                NativeMethods.INPUT[]    inputs = new NativeMethods.INPUT[2];
                NativeMethods.MOUSEINPUT mi     = new NativeMethods.MOUSEINPUT();
                inputs[0].type = NativeMethods.INPUT_MOUSE;
                inputs[1].type = NativeMethods.INPUT_MOUSE;
                mi.dx          = 0;
                mi.dy          = 0;
                switch (button)
                {
                case MouseButtons.None:
                    return(false);

                case MouseButtons.Left:
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_LEFTDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_LEFTUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.Right:
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_RIGHTDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_RIGHTUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.Middle:
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_MIDDLEDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_MIDDLEUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.XButton1:
                    mi.mouseData      = NativeMethods.XBUTTON1;
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_XDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_XUP;
                    inputs[1].mkhi.mi = mi;
                    break;

                case MouseButtons.XButton2:
                    mi.mouseData      = NativeMethods.XBUTTON2;
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_XDOWN;
                    inputs[0].mkhi.mi = mi;
                    mi.dwFlags        = NativeMethods.MOUSEEVENTF_XUP;
                    inputs[1].mkhi.mi = mi;
                    break;
                }

                if (!ci.PrepareWindowForInput())
                {
                    ci.DetachFromWindow();
                    return(false);
                }

                NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
                if (NativeMethods.GetWindowPlacement(ci.WindowHandle, ref wp))
                {
                    /*int screenX = wp.rcNormalPosition.X + x;
                     * int screenY = wp.rcNormalPosition.Y + y;
                     * int absX = (screenX * 65536 / Screen.PrimaryScreen.Bounds.Width);
                     * int absY = (screenY * 65536 / Screen.PrimaryScreen.Bounds.Height);
                     * inputs[0].mkhi.mi.dx = absX;
                     * inputs[1].mkhi.mi.dx = absX;
                     * inputs[0].mkhi.mi.dy = absY;
                     * inputs[1].mkhi.mi.dy = absY;*/

                    // using this method because absolute position is always off by a pixel or 2

                    if (!NativeMethods.SetCursorPos(x + wp.rcNormalPosition.X, y + wp.rcNormalPosition.Y))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                uint success = NativeMethods.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(inputs[0]));
                if (doubleClick && success == inputs.Length)
                {
                    success = NativeMethods.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(inputs[0]));
                }
                ci.DetachFromWindow();
                return(success == inputs.Length);
            }
            return(false);
        }