2010-05-27 58 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