public bool TryGetClickablePoint(out Point pt) { pt = new Point(); tagPOINT clickable; if (IUIAutomationElement.GetClickablePoint(clickable: out clickable) == 0) { return(false); } pt.X = clickable.x; pt.Y = clickable.y; return(true); }
private void timer1_Tick(object sender, EventArgs e) { if (count < 4) { title = list[count]; count++; } else { count = 0; title = list[count]; count++; } //找到QQ Process[] process = Process.GetProcessesByName("QQ"); foreach (Process p in process) { textBox1.Clear(); //從QQ產生root automation IUIAutomationElement _viveportAutomationElement = _automation.ElementFromHandle( p.MainWindowHandle); if (_viveportAutomationElement == null) { throw new InvalidOperationException("QQ must be running"); } //依據屬性名稱 找出tabbox IUIAutomationCondition conditionNote = _automation.CreatePropertyCondition( _propertyIdName, title); IUIAutomationElement _tabBoxAutomationElement = _viveportAutomationElement.FindFirst( TreeScope.TreeScope_Descendants, conditionNote); if (_tabBoxAutomationElement == null) { throw new InvalidOperationException("Could not find " + title); } //由tab找出按鍵範圍 移動游標點擊 tagPOINT point = new tagPOINT(); _tabBoxAutomationElement.GetClickablePoint(out point); Cursor.Position = new Point((int)point.x, (int)point.y); LeftClick(); Thread.Sleep(150); //找出QQ聊天室顯示框 conditionNote = _automation.CreatePropertyCondition( _propertyIdName, "消息"); IUIAutomationElement _resultTextBoxAutomationElement = _viveportAutomationElement.FindFirst( TreeScope.TreeScope_Descendants, conditionNote); if (_resultTextBoxAutomationElement == null) { throw new InvalidOperationException("Could not find 消息"); } //取出消息 UIAutomationClient.IUIAutomationLegacyIAccessiblePattern legacyPattern1 = (UIAutomationClient.IUIAutomationLegacyIAccessiblePattern)_resultTextBoxAutomationElement.GetCurrentPattern(patternId); //放到texebox List <char> list = legacyPattern1.CurrentValue.ToList(); foreach (char i in list) { if (i != '\r') { textBox1.AppendText(i.ToString()); } else { textBox1.AppendText(Environment.NewLine); } } } }