コード例 #1
0
        /// <summary>
        /// Get the top level DesktopElement from Windows handle
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        public static DesktopElement ElementFromHandle(IntPtr hWnd)
        {
            try
            {
                return(ElementFromUIAElement(UIAutomation.ElementFromHandle(hWnd)));
            }
            catch
            {
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Get the top level DesktopElement from Windows handle
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        public static DesktopElement ElementFromHandle(IntPtr hWnd)
        {
            try
            {
                return(ElementFromUIAElement(UIAutomation.ElementFromHandle(hWnd)));
            }
            catch (Exception e)
            {
                e.ReportException();
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Get the top level DesktopElement from Windows handle
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        public static DesktopElement ElementFromHandle(IntPtr hWnd)
        {
            try
            {
                return(ElementFromUIAElement(UIAutomation.ElementFromHandle(hWnd)));
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
            }
#pragma warning restore CA1031 // Do not catch general exception types

            return(null);
        }
コード例 #4
0
        static public MSGF_Data ParseMineSweeperGameField()
        {
            MSGF_Data result = new MSGF_Data();

            result.Xcells = 0;

            appElement = _automation.ElementFromHandle(MineSweeperHWND);

            var array_rows = appElement.FindAll(TreeScope.TreeScope_Children, _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_CustomControlTypeId));

            if (array_rows.Length > 1)
            {
                result.RowsCount = array_rows.Length - 1;

                /*var elem_texts = array_rows.GetElement(0).FindAll(TreeScope.TreeScope_Children, _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_TextControlTypeId));
                 * if (elem_texts.Length == 2)
                 * {
                 *  result.TimeSecs = Convert.ToInt32(elem_texts.GetElement(0).GetCurrentPropertyValue(UIA_PropertyIds.UIA_ValueValuePropertyId));
                 *  result.RemainingMines = Convert.ToInt32(elem_texts.GetElement(1).GetCurrentPropertyValue(UIA_PropertyIds.UIA_ValueValuePropertyId));
                 * }*/

                // Ищем ячейки
                for (int j = 1; j < array_rows.Length; j++)
                {
                    var elem_row    = array_rows.GetElement(j);
                    var array_cells = elem_row.FindAll(TreeScope.TreeScope_Children, _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId));

                    if (j == 1)
                    {
                        result.ColsCount = array_cells.Length;
                        result.cells     = new MSGF_Cell[result.ColsCount, result.RowsCount];
                    }

                    for (int i = 0; i < array_cells.Length; i++)
                    {
                        {
                            string nm = array_cells.GetElement(i).CurrentName;
                            result.cells[i, j - 1].elem = array_cells.GetElement(i); // Runtime Error Out of range


                            if (nm.Contains("помечена"))
                            {
                                result.cells[i, j - 1].state = -2; continue;
                            }
                            if (nm.Contains("неоткрыта"))
                            {
                                result.cells[i, j - 1].state = -1; result.Xcells++; continue;
                            }
                            if (nm.Contains("мин нет"))
                            {
                                result.cells[i, j - 1].state = 0; continue;
                            }
                            if (nm.Contains("ячейки: 1"))
                            {
                                result.cells[i, j - 1].state = 1; continue;
                            }
                            if (nm.Contains("ячейки: 2"))
                            {
                                result.cells[i, j - 1].state = 2; continue;
                            }
                            if (nm.Contains("ячейки: 3"))
                            {
                                result.cells[i, j - 1].state = 3; continue;
                            }
                            if (nm.Contains("ячейки: 4"))
                            {
                                result.cells[i, j - 1].state = 4; continue;
                            }
                            if (nm.Contains("ячейки: 5"))
                            {
                                result.cells[i, j - 1].state = 5; continue;
                            }
                            if (nm.Contains("ячейки: 6"))
                            {
                                result.cells[i, j - 1].state = 6; continue;
                            }
                            if (nm.Contains("ячейки: 7"))
                            {
                                result.cells[i, j - 1].state = 7; continue;
                            }
                            if (nm.Contains("ячейки: 8"))
                            {
                                result.cells[i, j - 1].state = 8; continue;
                            }
                        }
                    }
                }
            }

            return(result);
        }