如何从CFArrayRef中删除CGWindowID?

时间:2015-10-01 09:33:23

标签: objective-c macos

我想从CFArrayRef

中删除windowId
CFArrayRef window2ids = CGWindowListCreate(kCGWindowListOptionOnScreenOnly ,
                                           kCGNullWindowID);

这可能吗?如果是这样的话?我用谷歌搜索,但我没有找到任何答案。

1 个答案:

答案 0 :(得分:1)

  CFArrayRef window2ids = CGWindowListCreate(kCGWindowListOptionOnScreenOnly ,
                                       kCGNullWindowID);
  NSMutableArray *mutArray = [NSMutableArray arrayWithArray:(__bridge_transfer NSMutableArray *)window2ids];
  id windowIamLookingFor;
  [mutArray indexOfObject:windowIamLookingFor];
  [mutArray removeObject:yourWindowId];
  CFArrayRef window3ids = (__bridge CFArrayRef)[mutArray copy];

或做corefoundation舞蹈

  CFArrayRef window2ids = CGWindowListCreate(kCGWindowListOptionOnScreenOnly ,
                                         kCGNullWindowID);
  CFMutableArrayRef mutWindowsIds = CFArrayCreateMutableCopy(NULL, 0, window2ids);
  CFRelease(window2ids);
  id windowIamLookingFor;
  CFIndex index = CFArrayGetFirstIndexOfValue(mutWindowsIds, CFRangeMake(0, CFArrayGetCount(window2ids)), (__bridge const void *)(windowIamLookingFor));
  CFArrayRemoveValueAtIndex(mutWindowsIds, index);
  CFRelease(mutWindowsIds);