예제 #1
0
        /// <summary>
        /// 获取顶层窗体(直到获取到为止)
        /// </summary>
        /// <param name="className"></param>
        /// <returns></returns>
        private int GetTopHwnd(GetHwndConfig hwndConfig)
        {
            int currenHwnd = 0;

            do
            {
                currenHwnd = GetHwndInfor.FindTopForm(hwndConfig.TopFromClassName, null);
                Thread.Sleep(1000);
            } while (currenHwnd == 0);

            for (int arrIndex = hwndConfig.LevelIndex.Count; arrIndex > 0; arrIndex--)
            {
                int indexCount = hwndConfig.LevelIndex[arrIndex - 1];
                if (indexCount != 0)
                {
                    for (int index = 0; index < (indexCount - 1); index++)
                    {
                        currenHwnd = GetHwndInfor.GetWindow(currenHwnd, GetWindowFlagEnum.GetNextHwnd);
                    }
                }

                if (arrIndex > 1)
                {
                    currenHwnd = GetHwndInfor.GetWindow(currenHwnd, GetWindowFlagEnum.GetChildFirstHwnd);
                }
            }
            addLoog("定位句柄位置成功");


            return(currenHwnd);
        }
예제 #2
0
        private void btnSelectHwnd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(_topFormClassName) || !string.IsNullOrEmpty(_topFormTitle))
            {
                TopWindowHwnd = GetHwndInfor.FindTopForm(_topFormClassName, _topFormTitle);
            }

            if (TopWindowHwnd != 0)
            {
                //收银系统
                if (!GetHwndInfor.TopShowForm(TopWindowHwnd))
                {
                    MessageBox.Show("置顶窗口失败", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


            Regex rg = new Regex("^(?<x>[0-9]+),(?<y>[0-9]+)$");

            if (rg.IsMatch(this.txtMousePoint.Text))
            {
                GroupCollection group = rg.Match(this.txtMousePoint.Text).Groups;
                Point           p     = new Point(int.Parse(group["x"].ToString()), int.Parse(group["y"].ToString()));

                iActiveHwnd = GetHwndInfor.MousePointGetHwnd(p);

                this.txtHwnd.Text      = iActiveHwnd.ToString();
                this.txtClassName.Text = GetHwndInfor.GetHwndClassName(iActiveHwnd);

                TopWindowHwnd = GetHwndInfor.GetTopFormHwnd(iActiveHwnd);

                //取消置顶
                if (!GetHwndInfor.CancelTopShowForm(TopWindowHwnd))
                {
                    MessageBox.Show("取消置顶窗口失败", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                _topFormClassName = GetHwndInfor.GetHwndClassName(TopWindowHwnd);
                _topFormTitle     = GetHwndInfor.GetHwndTitle(TopWindowHwnd);

                this.txtTitle.Text = string.Format("顶层窗体类名:{0}\r\n顶层窗体题名:{1}", _topFormClassName, _topFormTitle);

                string tempTitle = GetHwndInfor.GetHwndTitle(iActiveHwnd);
                Regex  rg2       = new Regex(@"^(?<NotNuber>\D*)");
                if (rg2.IsMatch(tempTitle))
                {
                    txtLikeTitle.Text = rg2.Match(tempTitle).Groups["NotNuber"].ToString();
                }
                else
                {
                    Regex rg3 = new Regex(@"(?<NotNuber>\D*)$");
                    if (rg3.IsMatch(tempTitle))
                    {
                        txtLikeTitle.Text = rg3.Match(tempTitle).Groups["NotNuber"].ToString();
                    }
                    else
                    {
                        txtLikeTitle.Text = tempTitle;
                    }
                }
            }
            else
            {
                MessageBox.Show("错误的鼠标位置,正确的格式(x,y):23,89", "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }