我有一个Windows窗体应用程序,它在执行时启动Firefox,抓取窗口的进程和句柄,并执行Firefox的屏幕截图,将其保存到磁盘(temp.bmp)并调用ProcessGetWindow。我基本上使用MODI中的MiSelectRects来捕获我正在寻找的单词周围的矩形,然后使用AutoIT鼠标单击该单词。MODI MiSelectRects获取坐标错误
问题是我的坐标从顶部偏离了大约10个像素。
任何想法可能是错误的?这是处理的功能。我已经将AutoIT处理注释掉了,我只是用一个MessageBox进行调试来显示实际的坐标。然后我用AutoIT的窗口信息工具确认,这绝对是关闭的...我做错了什么,或者是有什么东西搞砸MODI?
public void ProcessGetWindow(Bitmap image)
{
Document modiDoc = null;
MiDocSearch modiSearch = null;
IMiSelectableItem modiTextSel = null;
MiSelectRects modiSelectRects = null;
MiSelectRect modiSelectRect = null;
MiRects modiRects = null;
int intSelInfoPN;
string intSelInfoTop;
int intSelInfoBottom;
string intSelInfoLeft;
int intSelInfoRight;
// Load an existing image file.
modiDoc = new Document();
modiDoc.Create(@"C:\\temp.bmp");
// Perform OCR.
modiDoc.Images[0].OCR();
// Search for the selected word.
modiSearch = new MiDocSearch();
modiSearch.Initialize(modiDoc, "Click Me", 0, 0, false, false);
modiSearch.Search(null, ref modiTextSel);
try
{
modiSelectRects = modiTextSel.GetSelectRects();
}
catch (COMException)
{
MessageBox.Show("Me thinks that the OCR didn't work right!");
}
foreach (MiSelectRect mr in modiSelectRects)
{
//intSelInfoPN = mr.PageNumber.ToString();
intSelInfoTop = mr.Top.ToString();
//intSelInfoBottom = mr.Bottom;
intSelInfoLeft = mr.Left.ToString();
//intSelInfoRight = mr.Right;
/*AutoItX3 auto = new AutoItX3();
auto.AutoItSetOption("MouseCoordMode", 2);
auto.MouseClick("", intSelInfoLeft, intSelInfoTop, 1, 80);*/
MessageBox.Show("Coordinates: " + intSelInfoLeft + ", " + intSelInfoTop, "Coordinates", MessageBoxButtons.OK);
}
//string textResult = modiTextSel.Text;
//MessageBox.Show(textResult, "Search Results", MessageBoxButtons.OK);
// Close this dialog.
Application.Exit();
}
仅供参考,微软已弃用MODI。当用户升级到Office 2010时,您将遇到问题。 – TrueWill