Reputation: 170390
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?
Upvotes: 1
Views: 10769
Reputation: 5882
I've implemented it with CFUserNotificationDisplayAlert
and it doesn't return until the user closes 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.
Upvotes: 6
Reputation: 170390
It looks that CreateStandardAlert
is the right solution because this one is modal.
DialogRef theItem;
DialogItemIndex itemIndex;
CreateStandardAlert(kAlertNoteAlert, CFSTR("aaa"), CFSTR("bbb"), NULL, &theItem);
RunStandardAlert(theItem, NULL, &itemIndex);
Upvotes: 4
Reputation: 170829
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.
Upvotes: 1