【问题标题】:Getting a notification when other app's window move / resize当其他应用程序的窗口移动/调整大小时收到通知
【发布时间】:2015-07-01 14:42:10
【问题描述】:

我正在创建一个屏幕抓取应用程序。我现在尝试的是在给定应用程序的活动窗口的角周围放置一个矩形(通过 PID)。

我通过获取对工作区中所有活动窗口的引用并使用CGWindowListCopyWindowInfo 来匹配所有者 PID 来管理它。现在我有一个活动窗口数组,但是在显示包含上述所有窗口的矩形之后,我没有找到一种方法来注册以在这些窗口被移动和/或调整大小以调整大小和适合我绘制的矩形。

以下是我用来获取所选应用程序的NSWindow 帧的代码示例。

pid_t pid = [selectedApplication processIdentifier];
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionAll,kCGNullWindowID);
for (NSMutableDictionary* entry in (NSArray*)windowList) {
      pid_t ownerPID = [[entry objectForKey:(id)kCGWindowOwnerPID] integerValue];
      if (pid == ownerPID) {
          // setting the bounds for each window of the application on match
          CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[entry objectForKey:(id)kCGWindowBounds], &bounds); 
.....

在给定我不拥有的应用程序的特定 PID 的情况下,我是否可以通过 NSwindows 注册更新?

【问题讨论】:

  • 您可以在 bugreport.apple.com 提交功能请求。

标签: cocoa nsnotificationcenter nswindow nsnotifications nsapplication


【解决方案1】:

目前这是来自 Apple 的 API 的限制。没有找到任何其他方式从其他应用程序NSWindows 注册更新NSNotifications。也许这被视为一种安全措施。

【讨论】:

猜你喜欢
  • 2019-10-18
  • 2011-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-04
  • 2014-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多