Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top