8
任何人都知道如何使用UI Automation和.Net從其他應用程序中獲取選定的文本?UI Automation「Selected text」
http://msdn.microsoft.com/en-us/library/ms745158.aspx
任何人都知道如何使用UI Automation和.Net從其他應用程序中獲取選定的文本?UI Automation「Selected text」
http://msdn.microsoft.com/en-us/library/ms745158.aspx
private void button1_Click(object sender, EventArgs e) {
Process[] plist = Process.GetProcesses();
foreach (Process p in plist) {
if (p.ProcessName == "notepad") {
AutomationElement ae = AutomationElement.FromHandle(p.MainWindowHandle);
AutomationElement npEdit = ae.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "Edit"));
TextPattern tp = npEdit.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
TextPatternRange[] trs;
if (tp.SupportedTextSelection == SupportedTextSelection.None) {
return;
}
else {
trs = tp.GetSelection();
lblSelectedText.Text = trs[0].GetText(-1);
}
}
}
}
縫好,將考驗 – 2010-03-05 01:34:35