1

CFUserNotificationDisplayAlertCFUserNotificationDisplayNotice创建了一个非模式窗口,这很糟糕,因为如果您选择原始应用程序窗口(消息框隐藏但应用程序不响应),它可能会使您的应用程序 UI 处于非常不希望的状态。

旧的SystemAlert是模态的,但这个不完全支持 Unicode 字符串。

如何在 Mac 下将消息框显示为模式窗口?我正在寻找类似于 Windows 中的 MessageBox 的东西?

4

3 回答 3

5

我已经实现了它,CFUserNotificationDisplayAlert并且在用户关闭 MessageBox 之前它不会返回。

如果你想看一下代码,我在 Mac 的 MessageBox 函数中有它, 你会发现一个为 mac 实现的 MessageBox 函数,它只为 MB_OKCANCEL 实现,但是更多的代码可以覆盖整个 MessageBox 标志和返回值, 是一个很好的起点。

于 2010-05-05T11:41:27.017 回答
3

看起来这CreateStandardAlert是正确的解决方案,因为这是modal


DialogRef theItem;
DialogItemIndex itemIndex;
CreateStandardAlert(kAlertNoteAlert, CFSTR("aaa"), CFSTR("bbb"), NULL, &theItem);
RunStandardAlert(theItem, NULL, &itemIndex);
于 2010-01-13T16:19:38.847 回答
1

看看NSBeginAlertSheet函数或 NSApp 的:

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

可能是你想要的。也是一篇关于使用工作表的好文章。

于 2010-01-13T13:19:07.637 回答