如何在 C++ 中显示模式消息框在 Mac 上?

发布于 2024-08-17 08:17:06 字数 606 浏览 1 评论 0原文

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不可一世的女人 2024-08-24 08:17:06

我已经使用 CFUserNotificationDisplayAlert 实现了它,并且直到用户关闭 MessageBox 后它才会返回。

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

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.

一影成城 2024-08-24 08:17:06

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


DialogRef theItem;
DialogItemIndex itemIndex;
CreateStandardAlert(kAlertNoteAlert, CFSTR("aaa"), CFSTR("bbb"), NULL, &theItem);
RunStandardAlert(theItem, NULL, &itemIndex);

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);
ゞ花落谁相伴 2024-08-24 08:17:06

看看 NSBeginAlertSheet 函数或 NSApp 的:

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

可能就是你想要的。 这里也是一篇不错的文章关于使用床单。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文