gpt4 book ai didi

objective-c - 如何使用 Objective-C 获取应用程序的详细信息?

转载 作者:行者123 更新时间:2023-12-03 16:45:01 30 4
gpt4 key购买 nike

我有以下代码来检测当前窗口。我如何获取 1) 应用程序内部名称、2) 位置、3) 发布者和 4) 窗口/应用程序的描述?

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

//Get info about the currently active application.
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSDictionary* currentAppInfo = [workspace activeApplication];

//Get the PSN of the current application.
UInt32 lowLong = [[currentAppInfo objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
UInt32 highLong = [[currentAppInfo objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
ProcessSerialNumber currentAppPSN = {highLong,lowLong};

//Grab window information from the window server.
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
ProcessSerialNumber myPSN = {kNoProcess, kNoProcess};

//Loop through the windows, the window list is ordered from front to back.
for (NSMutableDictionary* entry in (NSArray*) windowList)
{
int pid = [[entry objectForKey:(id)kCGWindowOwnerPID] intValue];
GetProcessForPID(pid, &myPSN);

//If the process of the current window in the list matches our process, get the front window number.
if(myPSN.lowLongOfPSN == currentAppPSN.lowLongOfPSN && myPSN.highLongOfPSN == currentAppPSN.highLongOfPSN)
{
NSNumber *windowNumber = [entry objectForKey:(id)kCGWindowNumber];
windowNumber = [entry objectForKey:(id)kCGWindowNumber];
NSString* applicationName = [entry objectForKey:(id)kCGWindowOwnerName];
NSLog(@"Capture the window: %@ with window ID: %@.",applicationName,windowNumber);
return applicationName;

//Break because we only want the front window.
break;
}
}
CFRelease(windowList);
[pool release];

最佳答案

您应该使用ProcessInformationCopyDictionary来自流程管理器 API 的函数。将 &myPSNkProcessDictionaryIncludeAllInformationMask 作为参数,您将获得您正在查找的信息。

关于objective-c - 如何使用 Objective-C 获取应用程序的详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1754160/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com