【问题标题】:How to display a modal message box in C++ on Mac?如何在 Mac 上的 C++ 中显示模态消息框?
【发布时间】:2010-01-13 13:08:20
【问题描述】:

CFUserNotificationDisplayAlertCFUserNotificationDisplayNotice 创建一个非模态窗口,这很糟糕,因为如果您选择原始应用程序窗口(消息框被隐藏,但应用程序没有响应)。

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

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

【问题讨论】:

    标签: 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 也是一篇关于工作表的好文章。

      【讨论】:

        猜你喜欢
        • 2011-05-31
        • 1970-01-01
        • 2020-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-02
        • 1970-01-01
        相关资源
        最近更新 更多