何获取自身程序在任务栏上的图标在屏幕上的位置坐标。

lgjgsslgjgss 2012-07-09 04:18:11
基本上,每个程序,在任务栏上都有图标。我想知道,这个图标在屏幕上的位置信息。

该如何获取?

下面这个帖子的方法,为什么在xp下成功了;但在win7下,却不无效果,获取的坐标都是0?



http://topic.csdn.net/u/20071116/00/3890ef46-dfa3-41ac-8337-61380bfb534c.html



















...全文
535 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
_周星星 2013-01-15
  • 打赏
  • 举报
回复
为什么上面的代码会报 未将对象引用设置到对象的实例。
lgjgsslgjgss 2012-07-11
  • 打赏
  • 举报
回复
解决了:


首先在程序集中,添加UIAutomationClient和UIAutomationTypes。

接着代码:



using System.Windows.Automation;


若Windows7系统下,采用:
AutomationElement aelement =
AutomationElement.RootElement
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.ClassNameProperty, "Shell_TrayWnd"))
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.ClassNameProperty, "ReBarWindow32"))
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.ClassNameProperty, "MSTaskSwWClass"))
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.ClassNameProperty, "MSTaskListWClass"))
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.NameProperty, 程序的标题字符串));

若XP系统下,采用:
AutomationElement aelement =
AutomationElement.RootElement
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.ClassNameProperty, "Shell_TrayWnd"))
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.ClassNameProperty, "ReBarWindow32"))
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.ClassNameProperty, "ToolbarWindow32"))
.FindFirst(TreeScope.Descendants,new PropertyCondition(AutomationElement.NameProperty, 程序的标题字符串));




然后,最终获取几何坐标信息:
if (aelement != null)
{

System.Windows.Rect rect = (System.Windows.Rect)
aelement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
}






lgjgsslgjgss 2012-07-10
  • 打赏
  • 举报
回复
请问使用UIAutomation怎么获取任务栏上的按钮的句柄啊?

搞了一天,网上的例子,都没有能够调成功的。

你那里有没有例子,能否帖个出来看看?



[Quote=引用 4 楼 的回复:]

UIAutomation
[/Quote]
lgjgsslgjgss 2012-07-09
  • 打赏
  • 举报
回复
果然够旁门左道啊。

厉害。这个方法显然是可以的,不过效率比较低。

不过你真厉害,图像的方法,你居然都能想到。


[Quote=引用 3 楼 的回复:]

屏幕截图,然后在截图中进行位图比较
不知道有没有高效的图形算法,不然比较起来要死人的!
[/Quote]
Saleayas 2012-07-09
  • 打赏
  • 举报
回复
UIAutomation
assky124 2012-07-09
  • 打赏
  • 举报
回复
屏幕截图,然后在截图中进行位图比较
不知道有没有高效的图形算法,不然比较起来要死人的!
lgjgsslgjgss 2012-07-09
  • 打赏
  • 举报
回复
但我找了很久,还是找不到在win7系统下的正确方法。




[Quote=引用 1 楼 的回复:]

因为xp跟win系统不一样,那么对应的内容(可能叫code)也不一样!

要知道同样的方法用在不同的位子上,怎么地也得改点东西,完封不动照旧肯定会XX的!
[/Quote]
xb12369 2012-07-09
  • 打赏
  • 举报
回复
因为xp跟win系统不一样,那么对应的内容(可能叫code)也不一样!

要知道同样的方法用在不同的位子上,怎么地也得改点东西,完封不动照旧肯定会XX的!

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧