我使用White
获取Microsoft Word窗口,将文档作为TextBox,如下所示:
Application a = Application.Attach(0x0000AC34);
Window w = a.GetWindow("Document1 - Word", InitializeOption.WithCache);
TextBox doc = w.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Document));
有没有办法获得插入符号的位置?我对屏幕坐标和文本中的位置感兴趣。
理想情况下,我在White
寻找一些东西。
如果没有,我知道我可以依靠AutomationElement
和TextPattern
即。
TextPattern tp = doc.AutomationElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
TextPatternRange[] selectionRanges = tp.GetSelection();
// etc...
这样做有什么缺点吗?我应该考虑更好的选择吗?
有没有办法可以访问IUIAutomationTextPattern2
界面?