- (NSArray *)subelementsfromElement:(AXUIElementRef)element forAttribute:(Nsstring *)attribute{ NSArray *subElements = nil; CFIndex count = 0; AXError result; result = AXUIElementGetAttributeValueCount(element,(CFStringRef)attribute,&count); if (result != kAXErrorSuccess) return nil; result = AXUIElementcopyAttributeValues(element,count,(CFArrayRef *)&subElements); if (result != kAXErrorSuccess) return nil; return [subElements autorelease];}- (AXUIElementRef)appDockIconByname:(Nsstring *)appname{ AXUIElementRef appElement = NulL; appElement = AXUIElementCreateApplication([[[NSRunningApplication runningApplicationsWithBundleIDentifIEr:@"com.apple.dock"] lastObject] processIDentifIEr]); if (appElement != NulL) { AXUIElementRef firstChild = (__brIDge AXUIElementRef)[[self subelementsfromElement:appElement forAttribute:@"AXChildren"] objectAtIndex:0]; NSArray *children = [self subelementsfromElement:firstChild forAttribute:@"AXChildren"]; NSEnumerator *e = [children objectEnumerator]; AXUIElementRef axElement; while (axElement = (__brIDge AXUIElementRef)[e nextObject]) { CFTypeRef value; ID TitleValue; AXError result = AXUIElementcopyAttributeValue(axElement,kAXTitleAttribute,&value); if (result == kAXErrorSuccess) { if (AXValueGetType(value) != kAXValueIllegalType) TitleValue = [NSValue valueWithPointer:value]; else TitleValue = (__brIDge ID)value; // assume toll-free brIDging if ([TitleValue isEqual:appname]) { return axElement; } } } } return nil;}- (voID)applicationDIDFinishLaunching:(NSNotification *)aNotification{ AXUIElementRef dockIcon = [self appDockIconByname:@"MYAPPname"]; if (dockIcon) { CFTypeRef value; CGPoint iconposition; AXError result = AXUIElementcopyAttributeValue(dockIcon,kAXpositionAttribute,&value); if (result == kAXErrorSuccess) { if (AXValueGetValue(value,kAXValueCGPointType,&iconposition)) { NSLog(@"position: (%f,%f)",iconposition.x,iconposition.y); } } }}总结
以上是内存溢出为你收集整理的使用Cocoa的Accessibility API获取应用程序停靠图标的位置全部内容,希望文章能够帮你解决使用Cocoa的Accessibility API获取应用程序停靠图标的位置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)