views:

289

answers:

3

CFUserNotificationDisplayAlert and CFUserNotificationDisplayNotice creates a non-modal window and this is bad because it could bring your application UI in a very undesired state if you select the original application window (the message box is hidden but the applicaton does not respond).

The old SystemAlert was modal but this one doesn't fully support Unicode strings.

How can i display a message box as a modal window under Mac? I'm looking for someting similar to MessageBox from Windows?

+1  A: 

Have a look at NSBeginAlertSheet function or at NSApp's:

- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow
      modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo

may be its what you want. Here is also a nice article about working with sheets.

Vladimir
+1  A: 
Sorin Sbarnea
A: 

I've implemented it with CFUserNotificationDisplayAlert and it doesn't return until the user coleses the MessageBox.

if you want to take a look of the code, I have it in MessageBox function in Mac there you will find a MessageBox function implemented for mac, it's only implemented for MB_OKCANCEL, but with little more code could cover the entire MessageBox flags and return values, is a good starting point

Jorge Arimany