Beispiel #1
0
        private int ItemIndex(string Item)
        {
            IntPtr MessageResult;
            IntPtr SendResult;

            SendResult = NM.SendMessageTimeout(Identity.Handle, NM.ComboBoxMessages.CB_FINDSTRINGEXACT, new IntPtr(-1), Item, NM.SendMessageTimeoutFlags.SMTO_NORMAL, GUI.m_APE.TimeOut, out MessageResult);
            if (SendResult == IntPtr.Zero) //Failed
            {
                throw new Exception("Failed to access the combobox");
            }
            else
            {
                return(unchecked ((int)MessageResult.ToInt64()));
            }
        }
Beispiel #2
0
        internal void SingleClickItemInternal(string itemText)
        {
            //locate the item
            int Index = ItemIndex(itemText);

            if (Index == NM.LB_ERR)
            {
                throw new Exception("Failed to find the item in the " + Description);
            }

            //Locate the rect of the item
            int Left;
            int Top;
            int Right;
            int Bottom;

            GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "GetItemRectangle", MemberTypes.Method, new Parameter(GUI.m_APE, Index));
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Left", MemberTypes.Property);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store3, "Top", MemberTypes.Property);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store4, "Right", MemberTypes.Property);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store5, "Bottom", MemberTypes.Property);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store5);
            GUI.m_APE.SendMessages(EventSet.APE);
            GUI.m_APE.WaitForMessages(EventSet.APE);
            //get the values returned
            Left   = GUI.m_APE.GetValueFromMessage();
            Top    = GUI.m_APE.GetValueFromMessage();
            Right  = GUI.m_APE.GetValueFromMessage();
            Bottom = GUI.m_APE.GetValueFromMessage();

            //scroll the item into view if needed
            NM.tagRect ClientRect;
            NM.GetClientRect(Identity.Handle, out ClientRect);

            if (((Bottom - Top) / 2) + Top > ClientRect.bottom || ((Bottom - Top) / 2) + Top < ClientRect.top)
            {
                // Currently APE doesn't support setting parameters or fields and I don't really want to add support as we should be doing things like a real user would
                //GUI.m_APE.AddMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                //GUI.m_APE.AddMessageQueryMember(DataStores.Store0, DataStores.Store1, "TopIndex", MemberTypes.Property, new Parameter(GUI.m_APE, Index));
                //GUI.m_APE.AddMessageQueryMember(DataStores.Store0, DataStores.Store2, "TopIndex", MemberTypes.);
                //GUI.m_APE.AddMessageGetValue(DataStores.Store2);
                //GUI.m_APE.SendMessages(EventSet.APE);
                //GUI.m_APE.WaitForMessages(EventSet.APE);
                ////get the values returned
                //int CurrentIndex = GUI.m_APE.GetValueFromMessage();
                IntPtr SendResult;
                IntPtr MessageResult;

                SendResult = NM.SendMessageTimeout(Identity.Handle, NM.ListBoxMessages.LB_SETTOPINDEX, new IntPtr(Index), IntPtr.Zero, NM.SendMessageTimeoutFlags.SMTO_NORMAL, GUI.m_APE.TimeOut, out MessageResult);
                if (SendResult == IntPtr.Zero || MessageResult.ToInt64() == NM.LB_ERR)  //Failed
                {
                    throw new Exception("Failed to access the listbox of the " + Description);
                }
                //Wait for animation to finish
                //base.WaitForAnimation(Identity.Handle, false);

                GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "GetItemRectangle", MemberTypes.Method, new Parameter(GUI.m_APE, Index));
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Left", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store3, "Top", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store4, "Right", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store5, "Bottom", MemberTypes.Property);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store5);
                GUI.m_APE.SendMessages(EventSet.APE);
                GUI.m_APE.WaitForMessages(EventSet.APE);
                //get the values returned
                Left   = GUI.m_APE.GetValueFromMessage();
                Top    = GUI.m_APE.GetValueFromMessage();
                Right  = GUI.m_APE.GetValueFromMessage();
                Bottom = GUI.m_APE.GetValueFromMessage();
            }

            //click the item
            base.SingleClickInternal(-1, ((Bottom - Top) / 2) + Top, MouseButton.Left, MouseKeyModifier.None);

            //wait for selected == item
            int       SelectedIndex;
            Stopwatch timer = Stopwatch.StartNew();

            do
            {
                GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "SelectedIndex", MemberTypes.Property);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1);
                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
                SelectedIndex = GUI.m_APE.GetValueFromMessage();

                if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut)
                {
                    throw new Exception("Failed to select the item in the " + Description);
                }

                Thread.Sleep(15);
            }while (SelectedIndex != Index);
            timer.Stop();
        }
Beispiel #3
0
        /// <summary>
        /// Selects the specified item in the combobox by clicking on it
        /// </summary>
        /// <param name="item">The item to select</param>
        public void SingleClickItem(string item)
        {
            Stopwatch timer;

            //Check if its already selected
            if (this.Text == item)
            {
                GUI.Log("Ensure " + Identity.Description + " is set to " + item, LogItemType.Action);
                return;
            }

            GUI.Log("Select [" + item + "] from " + Identity.Description, LogItemType.Action);

            //Get the style
            GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "DropDownStyle", MemberTypes.Property);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "ToString", MemberTypes.Method);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store3, "DroppedDown", MemberTypes.Property);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
            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
            string Style       = GUI.m_APE.GetValueFromMessage();
            bool   DroppedDown = GUI.m_APE.GetValueFromMessage();

            IntPtr ListBox = IntPtr.Zero;

            Input.Block(Identity.ParentHandle, Identity.Handle);
            try
            {
                if (Style == "Simple")
                {
                    //get the Simple mode listbox child window
                    GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "childListBox", MemberTypes.Field);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Handle", MemberTypes.Property);
                    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
                    ListBox = (IntPtr)GUI.m_APE.GetValueFromMessage();
                }
                else
                {
                    if (!DroppedDown)
                    {
                        //show the dropdown
                        base.SingleClickInternal(Width - 5, -1, MouseButton.Left, MouseKeyModifier.None);
                    }

                    //find the dropdown
                    Input.WaitForInputIdle(Identity.Handle, GUI.m_APE.TimeOut);
                    GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "dropDownHandle", MemberTypes.Field);
                    GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1);
                    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
                    dynamic DroppedDownHandle = GUI.m_APE.GetValueFromMessage();

                    if (DroppedDownHandle == null)
                    {
                        throw new Exception("Failed to find the ComboBox dropdown");
                    }

                    ListBox = DroppedDownHandle;
                }

                //locate the item
                int Index = ItemIndex(item);
                if (Index == NM.CB_ERR)
                {
                    throw new Exception("Failed to find the ComboBox item");
                }

                IntPtr     MessageResult;
                IntPtr     SendResult;
                NM.tagRect ItemRect = new NM.tagRect();

                //Locate the rect of the item
                SendResult = NM.SendMessageTimeout(ListBox, NM.ListBoxMessages.LB_GETITEMRECT, new IntPtr(Index), ref ItemRect, NM.SendMessageTimeoutFlags.SMTO_NORMAL, GUI.m_APE.TimeOut, out MessageResult);
                if (SendResult == IntPtr.Zero || unchecked ((int)MessageResult.ToInt64()) == NM.LB_ERR)  //Failed
                {
                    throw new Exception("Failed to access the combobox");
                }

                NM.tagRect ClientRect;
                NM.GetClientRect(ListBox, out ClientRect);

                //scroll the item into view if needed
                if (((ItemRect.bottom - ItemRect.top) / 2) + ItemRect.top > ClientRect.bottom || ((ItemRect.bottom - ItemRect.top) / 2) + ItemRect.top < ClientRect.top)
                {
                    SendResult = NM.SendMessageTimeout(ListBox, NM.ListBoxMessages.LB_SETTOPINDEX, new IntPtr(Index), ref ItemRect, NM.SendMessageTimeoutFlags.SMTO_NORMAL, GUI.m_APE.TimeOut, out MessageResult);
                    if (SendResult == IntPtr.Zero || unchecked ((int)MessageResult.ToInt64()) == NM.LB_ERR)  //Failed
                    {
                        throw new Exception("Failed to access the combobox");
                    }

                    //Locate the rect of the item
                    SendResult = NM.SendMessageTimeout(ListBox, NM.ListBoxMessages.LB_GETITEMRECT, new IntPtr(Index), ref ItemRect, NM.SendMessageTimeoutFlags.SMTO_NORMAL, GUI.m_APE.TimeOut, out MessageResult);
                    if (SendResult == IntPtr.Zero || unchecked ((int)MessageResult.ToInt64()) == NM.LB_ERR)  //Failed
                    {
                        throw new Exception("Failed to access the combobox");
                    }
                }

                //click the item
                IntPtr temp = Identity.Handle;
                try
                {
                    Identity.Handle = ListBox;
                    base.SingleClickInternal(-1, ((ItemRect.bottom - ItemRect.top) / 2) + ItemRect.top, MouseButton.Left, MouseKeyModifier.None);
                }
                finally
                {
                    Identity.Handle = temp;
                }

                //wait for .Text to == text
                string CurrentText;
                timer = Stopwatch.StartNew();
                do
                {
                    CurrentText = GUI.m_APE.GetWindowTextViaWindowMessage(Identity.Handle);

                    if (CurrentText == item)
                    {
                        break;
                    }

                    if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut)
                    {
                        throw new Exception("Failed to set the text of the ComboBox");
                    }

                    Thread.Sleep(15);
                }while (true);
                timer.Stop();
            }
            finally
            {
                Input.Unblock();
            }
        }