2010-05-27 54 views
0

我试图从一个非常简单的应用程序内创建一个简单的对话框。它是应用程序中唯一的UI。但是当我调用RunStandardAlert时,这些按钮是不响应的,并且函数调用永远不会返回。我没有在应用程序的其他地方使用Carbon或Cocoa。RunStandardAlert永不返回,按钮没有响应

这是我使用的代码,来自Carbon教程。我直接从我的main()函数调用这个函数,但我也尝试在使用InstallEventLoopTimer()注册一个事件循环计时器之后调用了RunApplicationEventLoop(),所以我可以从那里调用下面的代码以防万一发生某些魔法时你运行你的应用程序事件循环来完成对话框工作所需的设置(voodoo!)。

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); 

回答

1

如果可执行文件不在应用程序包中,您将无法收到事件。

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; 
} 

然后,通过

$ gcc foo.c -o foo -framework Carbon 

编译它,现在你需要创建一个目录

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

,然后把二进制foo

foo.app/Contents/MacOS/foo 

现在你可以调用

$ open foo.app 

$ foo.app/Contents/MacOS/foo 

Bundle Programming Guide