获取win10桌面文件信息及坐标并模拟鼠标双击

网上找到的 都是这种windowAPI的方式 来获取桌面  资源图标 好像只针对xp可用 win10 捣鼓了半天也不行,最后自己通过UIAutomation 写了一套 下见代码

 基本思路:

1.获取当前桌面的根 System.Windows.Automation.AutomationElement。

2.根据根节点获取类名为 SysListView32 的list控件类型 对象(类名可用spy++查看)

3.遍历所有的ListItem

//查看桌面所有

  1.            var desktop = AutomationElement.RootElement;
  2.             var window = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "SysListView32"));
  3.             var test = window.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.IsEnabledProperty, true));
  4.             string[] ElementNames = new string[test.Count];
  5.             Int32 Cnt = 0;
  6.             foreach (AutomationElement aeWin in test)
  7.             {
  8.                 ElementNames[Cnt++] = "Automation ID : " + aeWin.Current.AutomationId.ToString() + ", Control Type : " + aeWin.Current.ControlType.ProgrammaticName.ToString() + ", Name : " + aeWin.Current.Name;
  9.             }

//获取某个快捷方式并打开

  1.   var disk= window.FindFirst(TreeScope.Descendants, new AndCondition(
  2.    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem),
  3.     new PropertyCondition(AutomationElement.NameProperty, "此电脑")));
  4.    var clickPattern = (InvokePattern)disk.GetCurrentPattern(InvokePattern.Pattern);
  5.     clickPattern.Invoke();

你可能感兴趣的:(获取win10桌面文件信息及坐标并模拟鼠标双击)