自动获取qq邮箱 测试版本qq2008

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Automation;
namespace QQEmail.Dal
{
    public class QQ
    {
        public DevExpress.XtraGrid.GridControl grid = new DevExpress.XtraGrid.GridControl();

        public bool isQQLoaded(ref int ProcessID)
        {               
              string machinename = System.Environment.MachineName;//获得计算机名
              Process[] processlist = Process.GetProcesses(machinename);//得到所有进程
         
              foreach (Process p in processlist)//列举每个进程
              {
                  if (p.ProcessName == "QQ")
                  {
                      ProcessID =p.Id;
                      return true;
                  }                
                
              }
              return false;           
        }
        public AutomationElement FindWindowByProcessId(int processId)
        {
            AutomationElement targetWindow = null;


            Process p = Process.GetProcessById(processId);
            targetWindow = AutomationElement.FromHandle(p.MainWindowHandle);
            return targetWindow;

        }

        public List<Model.QQ> getList( )
        {
            List<Model.QQ> list = new List<QQEmail.Model.QQ>();
            int pid=0;
            if (isQQLoaded(ref pid) )
            {
                AutomationElement aeDeskTop = FindWindowByProcessId(pid);
                AutomationElement seekPanel = aeDeskTop.FindFirst(TreeScope.Element, new PropertyCondition(AutomationElement.ClassNameProperty, "#32770"));
               
                if (seekPanel == null)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("请打开搜索面板");
                }
                else
                {
                    AutomationElement tabControls = seekPanel.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "SysTabControl32"));

                    AutomationElement city = tabControls.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "ComboBox"));
                    AutomationElement nextButton = tabControls.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "下页"));
                    while (nextButton.Current.IsEnabled)
                    {
                      
                        foreach (AutomationElement ae in tabControls.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem)))
                        {
                            Queue<string> lst = new Queue<string>();
                            foreach (AutomationElement subAe in ae.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)))
                            {
                                lst.Enqueue(subAe.Current.Name);
                            }
                            Model.QQ model = new QQEmail.Model.QQ();
                            model.Code = lst.Dequeue();
                            model.Name = lst.Dequeue();
                            model.Sex = lst.Dequeue();
                            model.Age = lst.Dequeue();
                            model.City = lst.Dequeue();
                            model.Email = model.Code + "@qq.com";
                            list.Add(model);

                        }
                        grid.Invoke(new EventHandler(delegate
                        {
                            grid.DataSource = list;
                        }));
                        InvokePattern ipClickButton = (InvokePattern)nextButton.GetCurrentPattern(InvokePattern.Pattern);

                        ipClickButton.Invoke();
                        System.Threading.Thread.Sleep(200);
                    }  //AutomationElement[] selectItems = (city.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern).Current.GetSelection();
                    //if (selectItems.Length > 0)
                    //{
                    //    SelectionItemPattern cityValue = (SelectionItemPattern)city.GtCurrentPattern(SelectionItemPattern.Pattern);
                        

                    //    cityValue.AddToSelection
                    //}
                    //foreach (AutomationElement ae in city.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)))
                    //{
                    //    SelectionItemPattern cityValue = (SelectionItemPattern)ae.GetCurrentPattern(SelectionItemPattern.Pattern);
                    //    cityValue.Select();
                    //}

                }
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请打开QQ(2008版)");
            }
            return list;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunjay117

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值