简体   繁体   English

RunStandardAlert永不返回,按钮无响应

[英]RunStandardAlert never returns, buttons are non-responsive

I'm trying to create a simple dialog box from within a very simple application. 我试图从一个非常简单的应用程序中创建一个简单的对话框。 It's the only UI in the application. 它是应用程序中唯一的UI。 But when I call RunStandardAlert, the buttons are non-responsive, and the function call never returns. 但是,当我调用RunStandardAlert时,按钮无响应,并且函数调用永不返回。 I am not using Carbon or Cocoa anywhere else in the app. 我在应用程序的其他任何地方都没有使用Carbon或Cocoa。

This is the code I am using, from the Carbon tutorial. 这是我在Carbon教程中使用的代码。 I am calling this directly from my main() function, but I have also tried calling calling RunApplicationEventLoop() after registering an event loop timer with InstallEventLoopTimer() so I could call the below code from there in case there was some magic going on when you run your application event loop that does the setup required for dialog boxes to work (voodoo!). 我直接从main()函数调用此函数,但是我也尝试过在InstallEventLoopTimer()注册事件循环计时器后调用RunApplicationEventLoop(),以便在发生某些魔术时可以从那里调用以下代码您运行您的应用程序事件循环,该循环执行对话框正常工作所需的设置(巫毒!)。

DialogRef theItem;
DialogItemIndex itemIndex;
CreateStandardAlert(kAlertStopAlert, CFSTR("Oh dear, the penguin’s disappeared."),
CFSTR("I hope you weren’t planning to open source him."), NULL, &theItem);
RunStandardAlert (theItem, NULL, &itemIndex);

You can't receive an event if the executable is not in an app bundle correctly. 如果可执行文件未正确放在应用程序捆绑包中,则您不会收到事件。

foo.c foo.c

#include <Carbon/Carbon.h>

int main(){
    DialogRef theItem;
    DialogItemIndex itemIndex;
    CreateStandardAlert(kAlertStopAlert, CFSTR("Oh dear, the penguin’s disappeared."),
    CFSTR("I hope you weren’t planning to open source him."), NULL, &theItem);
    RunStandardAlert (theItem, NULL, &itemIndex);
    return 0;
}

Then you compile it by 然后你编译它

$ gcc foo.c -o foo -framework Carbon

Now you need to create a directory 现在您需要创建一个目录

foo.app
foo.app/Contents
foo.app/Contents/MacOS

and then put the binary foo in 然后放入二进制foo

foo.app/Contents/MacOS/foo

Now you can either call 现在您可以打电话

$ open foo.app

or 要么

$ foo.app/Contents/MacOS/foo

See Bundle Programming Guide . 请参阅《 捆绑编程指南》

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM