Xcode を使ってQUITを押すと終了するプログラムを作ってみました。
戻る![]()
#include <Carbon/Carbon.h> #define BUTTON1 'BTN1'
pascal OSStatus MainWindowEventHandler(EventHandlerCallRef myHandler, EventRef event, void *userData) ; pascal OSStatus MainWindowEventHandler(EventHandlerCallRef myHandler, EventRef event, void *userData)
{
OSStatus result = eventNotHandledErr ;
HICommand command ; GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof (HICommand), NULL, &command ) ;
switch (command.commandID)
{ case BUTTON1 :
QuitApplicationEventLoop() ;
break ; }
return result;
} int main(int argc, char* argv[])
{
IBNibRef nibRef ;
WindowRef window ;
OSStatus err ;
EventTypeSpec mainSpec = {kEventClassCommand, kEventCommandProcess } ; err = CreateNibReference(CFSTR("main"), &nibRef) ;
require_noerr(err, CantGetNibRef) ;
err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")) ;
require_noerr(err, CantSetMenuBar) ;
err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window) ;
require_noerr(err, CantCreateWindow) ; DisposeNibReference(nibRef) ; err = InstallWindowEventHandler( window,
NewEventHandlerUPP(MainWindowEventHandler),
1,
&mainSpec,
(void *)window,
NULL
) ;
ShowWindow(window) ; RunApplicationEventLoop() ; CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:
return err ;
}