Exemplo n.º 1
0
        /// <summary>
        /// Closes the form by click the 'x' in the top right hand corner of the form
        /// </summary>
        public void Close()
        {
            if (NM.IsWindow(Identity.Handle))
            {
                if (NM.IsWindowVisible(Identity.Handle))
                {
                    if (NM.IsIconic(Identity.Handle))
                    {
                        throw new Exception("Can not close the window as it is minimised");
                    }

                    GUI.m_APE.AddFirstMessageGetTitleBarItemRectangle(Identity.Handle, NM.TitleBarStateElement.Close);
                    GUI.m_APE.SendMessages(EventSet.APE);
                    GUI.m_APE.WaitForMessages(EventSet.APE);
                    //Get the value(s) returned MUST be done straight after the WaitForMessages call
                    NM.StateSystem State  = (NM.StateSystem)GUI.m_APE.GetValueFromMessage();
                    int            Top    = GUI.m_APE.GetValueFromMessage();
                    int            Left   = GUI.m_APE.GetValueFromMessage();
                    int            Bottom = GUI.m_APE.GetValueFromMessage();
                    int            Right  = GUI.m_APE.GetValueFromMessage();

                    // Check the close button is actually displayed
                    if (State != NM.StateSystem.STATE_SYSTEM_NORMAL && State != NM.StateSystem.STATE_SYSTEM_PRESSED)
                    {
                        throw new Exception("Can not close the window as the close button is in state '" + State.ToString() + "'");
                    }

                    NM.tagRect WindowRect;
                    NM.GetWindowRect(Identity.Handle, out WindowRect);

                    int X = Left + ((Right - Left) / 2) - WindowRect.left;
                    int Y = Top + ((Bottom - Top) / 2) - WindowRect.top;

                    Input.Block(Identity.ParentHandle, Identity.Handle);
                    try
                    {
                        GUI.Log("Close the " + Identity.Description, LogItemType.Action);
                        base.SingleClickInternal(X, Y, MouseButton.Left, MouseKeyModifier.None);

                        //Wait for the window to disappear
                        base.WaitForControlToNotBeVisible();
                    }
                    finally
                    {
                        Input.Unblock();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Restores the window back clicking the restore button in the top right corner of the form
        /// Note if the window is minimised then a non-gui method is used to restore the form
        /// </summary>
        public void Restore()
        {
            GUI.Log("Restore the " + Identity.Description, LogItemType.Action);

            string windowState = FormWindowState();

            if (windowState == "Normal")
            {
                throw new Exception("Can not restore the window as it already is");
            }

            if (windowState == "Minimized")
            {
                Input.Block(Identity.ParentHandle, Identity.Handle);
                try
                {
                    NM.ShowWindow(Identity.Handle, NM.SW_RESTORE);

                    //Bring it to the front (can sometimes get restored to the background using the api)
                    SetFocus();

                    // Wait for the animation to finish
                    base.WaitForAnimation(Identity.Handle, true, AnimationUtils.WaitForAnimationSource.Form);

                    // Check the window is now normal
                    Stopwatch timer = Stopwatch.StartNew();
                    do
                    {
                        GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                        GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "WindowState", MemberTypes.Property);
                        GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "ToString", MemberTypes.Method);
                        GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
                        GUI.m_APE.SendMessages(EventSet.APE);
                        GUI.m_APE.WaitForMessages(EventSet.APE);
                        //Get the value(s) returned MUST be done straight after the WaitForMessages call
                        windowState = GUI.m_APE.GetValueFromMessage();

                        if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut)
                        {
                            timer.Stop();
                            throw new Exception("Failed to restore the window");
                        }

                        Thread.Sleep(15);
                    }while (windowState != "Normal");
                    timer.Stop();
                }
                finally
                {
                    Input.Unblock();
                }
            }
            else
            {
                GUI.m_APE.AddFirstMessageGetTitleBarItemRectangle(Identity.Handle, NM.TitleBarStateElement.Maximize);
                GUI.m_APE.SendMessages(EventSet.APE);
                GUI.m_APE.WaitForMessages(EventSet.APE);
                //Get the value(s) returned MUST be done straight after the WaitForMessages call
                NM.StateSystem State  = (NM.StateSystem)GUI.m_APE.GetValueFromMessage();
                int            Top    = GUI.m_APE.GetValueFromMessage();
                int            Left   = GUI.m_APE.GetValueFromMessage();
                int            Bottom = GUI.m_APE.GetValueFromMessage();
                int            Right  = GUI.m_APE.GetValueFromMessage();

                // Check the maximise button is actually displayed
                if (State != NM.StateSystem.STATE_SYSTEM_NORMAL && State != NM.StateSystem.STATE_SYSTEM_PRESSED)
                {
                    throw new Exception("Can not restore the window as the restore button is in state '" + State.ToString() + "'");
                }

                NM.tagRect WindowRect;
                NM.GetWindowRect(Identity.Handle, out WindowRect);

                int X = Left + ((Right - Left) / 2) - WindowRect.left;
                int Y = Top + ((Bottom - Top) / 2) - WindowRect.top;

                Input.Block(Identity.ParentHandle, Identity.Handle);
                try
                {
                    base.SingleClickInternal(X, Y, MouseButton.Left, MouseKeyModifier.None);

                    // Wait for the animation to finish
                    base.WaitForAnimation(Identity.Handle, true, AnimationUtils.WaitForAnimationSource.Form);

                    // Check the window is now minimised
                    Stopwatch timer = Stopwatch.StartNew();
                    do
                    {
                        GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                        GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "WindowState", MemberTypes.Property);
                        GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "ToString", MemberTypes.Method);
                        GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
                        GUI.m_APE.SendMessages(EventSet.APE);
                        GUI.m_APE.WaitForMessages(EventSet.APE);
                        //Get the value(s) returned MUST be done straight after the WaitForMessages call
                        windowState = GUI.m_APE.GetValueFromMessage();

                        if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut)
                        {
                            timer.Stop();
                            throw new Exception("Failed to restore the window");
                        }

                        Thread.Sleep(15);
                    }while (windowState != "Normal");
                    timer.Stop();
                }
                finally
                {
                    Input.Unblock();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Minimises the form by clicking the minimise button in the top right hand corner of the form
        /// </summary>
        public void Minimise()
        {
            GUI.Log("Minimise the " + Identity.Description, LogItemType.Action);

            string windowState = FormWindowState();

            if (windowState == "Minimized")
            {
                throw GUI.ApeException("Can not minimise the window as it already is");
            }

            GUI.m_APE.AddFirstMessageGetTitleBarItemRectangle(Identity.Handle, NM.TitleBarStateElement.Minimize);
            GUI.m_APE.SendMessages(EventSet.APE);
            GUI.m_APE.WaitForMessages(EventSet.APE);
            //Get the value(s) returned MUST be done straight after the WaitForMessages call
            NM.StateSystem State  = (NM.StateSystem)GUI.m_APE.GetValueFromMessage();
            int            Top    = GUI.m_APE.GetValueFromMessage();
            int            Left   = GUI.m_APE.GetValueFromMessage();
            int            Bottom = GUI.m_APE.GetValueFromMessage();
            int            Right  = GUI.m_APE.GetValueFromMessage();

            // Check the maximise button is actually displayed
            if (State != NM.StateSystem.STATE_SYSTEM_NORMAL && State != NM.StateSystem.STATE_SYSTEM_PRESSED)
            {
                throw GUI.ApeException("Can not minimise the window as the minimised button is in state '" + State.ToString() + "'");
            }

            NM.tagRect WindowRect;
            NM.GetWindowRect(Identity.Handle, out WindowRect);

            int X = Left + ((Right - Left) / 2) - WindowRect.left;
            int Y = Top + ((Bottom - Top) / 2) - WindowRect.top;

            Input.Block();
            try
            {
                base.SingleClickInternal(X, Y, MouseButton.Left, MouseKeyModifier.None, 32, 32);

                // Wait for the animation to finish
                base.WaitForAnimation(Identity.Handle, true, AnimationUtils.WaitForAnimationSource.Form);

                // Check the window is now minimised
                Stopwatch timer = Stopwatch.StartNew();
                do
                {
                    windowState = FormWindowState();

                    if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut)
                    {
                        timer.Stop();
                        throw GUI.ApeException("Failed to minimise the window");
                    }

                    Thread.Sleep(15);
                }while (windowState != "Minimized");
                timer.Stop();
            }
            catch when(Input.ResetInputFilter())
            {
                // Will never be reached as ResetInputFilter always returns false
            }
            finally
            {
                Input.Unblock();
            }
        }