同步调用 NSWindow makeKeyAndOrderFront

发布于 2024-11-26 10:23:24 字数 334 浏览 1 评论 0原文

我正在为 Mac OS 编写一个小型 Cocoa 应用程序,我的目标是显示一个窗口,然后读取屏幕上的像素。我已经知道如何执行后一部分,但在继续之前无法显示窗口。据我所知,像 NSWindow 的 makeKeyAndOrderFront 触发的窗口更新会被推迟。

我对 Cocoa 还比较陌生,但我基本上想做这样的事情:

[myWindow makeKeyAndOrderFront:self];
// application blocks right here until the window is actually shown
...

那么我如何使阻塞操作发生呢?

I am writing a small Cocoa application for Mac OS, and my goal is to show a window, and then read the pixels on the screen. I already know how to do the latter part, but am having trouble with having the window show up before proceeding. From what I've seen, window updates like the ones triggered by NSWindow's makeKeyAndOrderFront are deferred.

I'm still relatively new to Cocoa, but I basically want to do something like this:

[myWindow makeKeyAndOrderFront:self];
// application blocks right here until the window is actually shown
...

So how do I make that blocking operation happen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无声静候 2024-12-03 10:23:24

也许您可以从窗口而不是屏幕获取像素?在 Mac OS X 上,(几乎)每个窗口都有自己的缓冲区(后备存储),无论它是否可见。即使系统对话框遮挡了窗口所在的屏幕区域,这也将确保您的测试能够正常工作。

Perhaps you could obtain the pixels from the window, rather than the screen? On Mac OS X, (nearly) every window has its own buffer (backing store), whether or not it is visible. This will also ensure your test works even if there is a system dialog obscuring the area of the screen where the window is placed.

無心 2024-12-03 10:23:24

尝试在窗口上调用 -[NSWindow display],这将强制它立即显示。

Try calling -[NSWindow display] on your window, that will force it to display immediately.

深居我梦 2024-12-03 10:23:24

只需将一个对象委托为窗口的 NSWindowDelegate 并在委托中调用 windowDidBecomeKey: 后即可截取屏幕截图。

Simply delegate an object as the window's NSWindowDelegate and take your screenshot once windowDidBecomeKey: is called in the delegate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文