开发者

How to display a modal message box in C++ on Mac?

开发者 https://www.devze.com 2022-12-16 01:51 出处:网络
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 ori

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 app开发者_如何学运维licaton 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?


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.


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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号