private void btnLikeHwnd_Click(object sender, EventArgs e) { List <int> list = GetHwndInfor.ClassNameAndTitleToParentHwnd(this.txtLikeTitle.Text, this.txtClassName.Text); if (list.Count == 1) { iActiveHwnd = list[0]; this.txtHwnd.Text = iActiveHwnd.ToString(); this.txtTitle.Text = GetHwndInfor.GetHwndTitle(iActiveHwnd); MessageBox.Show("获取成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(string.Format("获取到{0}个相同符合条件的句柄位置。", list.Count), "不能唯一确定", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void SynData(object config) { try { GetHwndConfig hwndConfig = (GetHwndConfig)config; int currenHwnd = GetTopHwnd(hwndConfig); while (true) { if (IsSrceenImage) { Bitmap bmp = GetHwndInfor.GetHwndImage(currenHwnd); Invoke(new Action(() => { this.pictureBox1.Image = bmp; bmp = OCRImage.ImageProcessing(bmp);//图像处理 string strTitle = OCRImage.OCRBitmpa(bmp).OCRContent; Invoke(new Action(() => { this.labOCRConten.Text = strTitle; addLoog("OCR识别到的内容为:" + strTitle); })); })); } else { string strTitle = GetHwndInfor.GetHwndTitle(currenHwnd); if (strTitle == "") { addLoog("开始重新定位"); currenHwnd = GetTopHwnd(hwndConfig); } Invoke(new Action(() => { this.labHwendTitle.Text = strTitle; addLoog("获取到句柄内容为:" + strTitle); })); } Thread.Sleep(1000); } } catch (Exception ex) { addLoog("异常:" + ex.Message); } }
private void GetHwndTitle() { try { while (true) { if (iActiveHwnd <= 0) { break; } this.Invoke(new Action(() => { this.txtTitle.Text = GetHwndInfor.GetHwndTitle(iActiveHwnd); })); Thread.Sleep(500); } } catch (Exception) { } }
private void btnLikeHwnd2_Click(object sender, EventArgs e) { List <int> list = GetHwndInfor.ClassNameAndTitleToParentHwnd(this.txtTopFormTitle.Text, this.txtTopFormClassName.Text); if (list.Count == 1) { int tempHwnd = list[0]; Regex rg = new Regex("^(?<x>[0-9]+),(?<y>[0-9]+)$"); if (rg.IsMatch(this.txtOffsetPoint.Text)) { GroupCollection group = rg.Match(this.txtOffsetPoint.Text).Groups; Point p = new Point(int.Parse(group["x"].ToString()), int.Parse(group["y"].ToString())); iActiveHwnd = GetHwndInfor.TopFromHwndAndOffsetPointGetHwnd(tempHwnd, p, this.txtParentClassName.Text); if (iActiveHwnd != 0) { this.txtHwnd.Text = iActiveHwnd.ToString(); this.txtTitle.Text = GetHwndInfor.GetHwndTitle(iActiveHwnd); MessageBox.Show("获取成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { this.txtHwnd.Text = "0"; this.txtTitle.Text = "获取失败"; } } else { MessageBox.Show("错误的鼠标位置,正确的格式(x,y):23,89", "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(string.Format("获取到{0}个相同符合条件的句柄位置。", list.Count), "不能唯一确定", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
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); } }