views:

23

answers:

1

I'm trying to create a simple dialog box from within a very simple application. It's the only UI in the application. But when I call RunStandardAlert, the buttons are non-responsive, and the function call never returns. I am not using Carbon or Cocoa anywhere else in the app.

This is the code I am using, from the Carbon tutorial. 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!).

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

You can't receive an event if the executable is not in an app bundle correctly.

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.app/Contents/MacOS/foo

Now you can either call

$ open foo.app

or

$ foo.app/Contents/MacOS/foo

See Bundle Programming Guide.

Yuji