0

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?

3 Answers3

1

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.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
0

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

Jon Hess
  • 14,237
  • 1
  • 47
  • 51
  • Kevin also had a great suggestion of reading the window's pixels directly. You might consider using the -[NSView lockFocus] method and -[NSBitmapImageRep initWithFocusedViewRect:] to read directly from a specific window's backing store. – Jon Hess Jul 28 '11 at 04:58
0

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

spudwaffle
  • 2,905
  • 1
  • 22
  • 29