【问题标题】:How to display a modal message box in C++ on Mac?如何在 Mac 上的 C++ 中显示模态消息框?
【发布时间】:2010-01-13 13:08:20
【问题描述】:
【问题讨论】:
标签:
c++
macos
modal-dialog
messagebox
【解决方案1】:
我已经用CFUserNotificationDisplayAlert 实现了它,并且在用户关闭 MessageBox 之前它不会返回。
如果你想看一下代码,我在MessageBox function in Mac
在那里你会发现一个为 mac 实现的 MessageBox 函数,它只是为 MB_OKCANCEL 实现的,但只需更多的代码就可以覆盖整个 MessageBox 标志和返回值,这是一个很好的起点。
【解决方案2】:
看起来CreateStandardAlert 是正确的解决方案,因为这是modal。
DialogRef theItem;
DialogItemIndex itemIndex;
CreateStandardAlert(kAlertNoteAlert, CFSTR("aaa"), CFSTR("bbb"), NULL, &theItem);
RunStandardAlert(theItem, NULL, &itemIndex);
【解决方案3】:
查看NSBeginAlertSheet 函数或 NSApp 的:
- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow
modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo
可能是你想要的。 Here 也是一篇关于工作表的好文章。